about selenium, not knowing what errors are - python

Here's my code and the error Python provides.
I'm a beginner using Python 3.6. Can anyone helps find out what's wrong? Many thanks.
#!/usr/bin/env python
#coding: utf-8
from selenium import webdriver
driver = webdriver.Chrome('C:\\Users\\Admin\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe')
browser = webdriver.Chrome()
browser.get('http://www.bing.com/')
Traceback:
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\cxy61.com - html\python spider\001 selenium import.py", line 8, in <module>
driver = webdriver.Chrome('C:\\Users\\Admin\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe')
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 140, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 229, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception: Chrome version must be >= 58.0.3029.0
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.14393 x86_64)

You have to take care of a couple of things as follows:
As you are using chromedriver v2.31 the error clearly states Chrome version must be >= 58.0.3029.0. So you need to bump up your Google Chrome version to v58.0 or above.
If you want to specify the absolute path of the chromedriver within single quotes '...' then you have to provide single forward slashes \ only.
If you are assigning the webdriver instance to the driver, you have to use the driver instance only to open any url
Here is your own code with the above mentioned changes:
from selenium import webdriver
driver = webdriver.Chrome(r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('http://www.bing.com/')

Related

Python Selenium Error: Cannot find Opera binary

i'm trying out Python Selenium with my main browser, Opera, but i get a massive error when i execute the script, here's the python script:
from selenium import webdriver
path = r"C:\Users\sleep\Programs\operadriver_win64\operadriver.exe"
driver = webdriver.Opera(executable_path=path)
driver.get('https://youtube.com')
And here's the error:
Traceback (most recent call last):
File "C:\Users\sleep\Programs\Status-Entrega\main.py", line 6, in <module>
driver = webdriver.Opera(executable_path=r'C:\Users\sleep\Programs\operadriver_win64\operadriver.exe')
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 79, in __init__
OperaDriver.__init__(self, executable_path=executable_path,
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 55, in __init__
ChromiumDriver.__init__(self,
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
(Driver info: operadriver=91.0.4472.77 (1cecd5c8a856bc2a5adda436e7b84d8d21b339b6-refs/branch-heads/4472#{#1246}),platform=Windows NT 10.0.19042 x86_64)
How can i fix this?
can you try this :
from selenium import webdriver
from selenium.webdriver.opera.options import Options
options = Options()
options.binary_location = r'C:\opera.exe path'
driver = webdriver.Opera(opera_options = options,
executable_path=r'C:\operadriver.exe path')
it might work, don't forget one is the opera path and one is the operadriver path
This link may help: https://github.com/operasoftware/operachromiumdriver/blob/master/examples/desktop.py
import time
from selenium import webdriver
from selenium.webdriver.chrome import service
webdriver_service = service.Service('path/to/operadriver')
webdriver_service.start()
driver = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)
driver.get('https://www.google.com/')
input_txt = driver.find_element_by_name('q')
input_txt.send_keys('operadriver\n')
time.sleep(5) #see the result
driver.quit()

How do I resolve this Selenium exception on a Mac thats says "chrome not reachable"?

I'm trying to learn how to automate web processes using Selenium and hopefully be able to build robust web scrapers and stuff. So, I just finished installing Pycharm and Selenium, and I am just trying to run a simple snippet of code that opens a web page in chrome, nothing too fancy. My code is as follows (it's in Python of course)
from selenium import webdriver
PATH = "/Users/Kudzie/Tools/chromedriver"
driver = webdriver.Chrome(PATH)
driver.get('https://orbitrevolution.tech')
So , when I run this code, I get this exception, and I have no idea how to solve this, I've tried reading past variations of this question but i didn't seem to get a solution that works. the exception is as follows
Traceback (most recent call last):
File "/Users/Kudzie/PycharmProjects/Web Scraper/main.py", line 5, in <module>
driver = webdriver.Chrome(PATH)
File "/Users/Kudzie/PycharmProjects/Web Scraper/venv/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/Users/Kudzie/PycharmProjects/Web Scraper/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Users/Kudzie/PycharmProjects/Web Scraper/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Users/Kudzie/PycharmProjects/Web Scraper/venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/Kudzie/PycharmProjects/Web Scraper/venv/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
Process finished with exit code 1
Try replacing this:
driver = webdriver.Chrome(PATH)
With this:
driver = webdriver.Chrome(executable_path=PATH)

Why I am having an error on send_keys using selenium python

I'm trying to make a script that logs me into my account automatically and I'm stuck at send_keys.
I have the latest version of selenium, I'm using python 2.7.18.
here is my script:
from selenium import webdriver
from time import sleep
username = 'username'
driver = webdriver.Chrome()
driver.get('https://www.instagram.com/')
sleep(4)
email = '//*[#id="react-root"]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input'
login = driver.find_element_by_xpath(email).send_keys(username)
The error is:
Traceback (most recent call last):
File "C:\Users\Jameel\Desktop\selenium1.py", line 14, in <module>
login = driver.find_element_by_xpath(email).send_keys(username)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 479, in send_keys
'value': keys_to_typing(value)})
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 633, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 321, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
line 242, in check_response
raise exception_class(message, screen, stacktrace) WebDriverException: Message: unknown error: call function result
missing 'value' (Session info: chrome=83.0.4103.61) (Driver info:
chromedriver=2.31.488763
(092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT
10.0.17763 x86_64)
I know the script isn't complete.
Generally different sites follow different design approaches, which doesn't allow normal script flow & needs additional steps to be added.
In you case, the default CSS style blocks your input. So, first click on that element( Which makes it as focused) then send your keys.
Element Attribute differences below,
Before click action
After click action

selenium.common.exceptions.SessionNotCreatedException: Message: session not created, selenium python

I have a problem, every, single, TIME
Basically this is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\Program Files (x86)\Google\Chrome Beta\Application\chrome.exe"
options.add_argument("--no-sandbox")
options.add_argument("--no-default-browser-check")
options.add_argument("--no-first-run")
options.add_argument("--disable-default-apps")
driver = webdriver.Chrome(options=options, executable_path="C:\Program Files (x86)\Google\Chrome Beta\Application\chromedriver.exe")
driver.get('https://www.youtube.com/')
and the error is
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
I used Pycharm and tried to use VS code with python 3.4 and 3.7 and 3.8.3
plz help me I'm getting tired of this.
Full error Log:
Traceback (most recent call last):
File "C:/Users/um/PycharmProjects/Selenium/main.py", line 10, in <module>
driver = webdriver.Chrome(options=options, executable_path="C:\Program Files (x86)\Google\Chrome Beta\Application\chromedriver.exe")
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to send message to renderer
(Session info: chrome=81.0.4044.83)
Your error is not
unable to send message to renderer
as you mentioned. According to the stack trace you posted the problem in the line 6
driver = webdriver.Chrome(options=options, executable_path="chromedriver.exe", )
and the problem is:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
It seems like you specified an invalid path to the chromedriver and Selenium is unable to initialize the driver and create a session.
You should also check the version of the chromedriver with the guide.
Here you can download the valid version (I have taken your Chrome version from the stacktrace).
yes it did start and then close with the error log above, and also i have the correct version

Can't open IE using selenium in python

I am running on a Windows 10 machine, Internet Explorer 11, python 3.6, selenium 3.4.3 with IEDriverServer 3.5. I am trying to open up IE using the following code.
from selenium import webdriver
import os
driverLocation = "C:\\Users\\JD\\PycharmProjects\\Lib\\IEDriverServer.exe"
os.environ["webdriver.ie.driver"] = driverLocation
driver = webdriver.Ie(driverLocation)
google = "https://google.com"
driver.get(google)
The output:
Traceback (most recent call last):
File "C:/Users/J/PycharmProjects/Automation/IE_Test.py", line 7, in <module>
driver = webdriver.Ie(driverLocation)
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\ie\webdriver.py", line 57, in __init__
desired_capabilities=capabilities)
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 98, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 188, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Invalid capabilities in alwaysMatch: unknown capability named platform
Any help would be greatly appreciated thanks.
UPDATE:
I added this to my previous code,
capabilities = DesiredCapabilities.INTERNETEXPLORER
print(capabilities["platform"])
print(capabilities["browserName"])
OUTPUT:
WINDOWS
internet explorer
File "C:\Users\JD\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Invalid capabilities in alwaysMatch: unknown capability named platform
UPDATE:
I have also tried setting the capabilities but still recieve the same error: "unknown capabilities named platform
caps = DesiredCapabilities.INTERNETEXPLORER.copy()
caps["platform"] = "WINDOWS"
caps["browserName"] = "internet explorer"
caps["requireWindowFocus"] = True
browser = webdriver.Ie(capabilities=caps,
executable_path="C:\\Users\\JD\\PycharmProjects\\Lib\\IEDriverServer.exe")
browser.get("https://www.facebook.com/")
I had the same problem for couple of days.
My workaround for this was to delete platform and version keys from capabilities dictionary
Example:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
#create capabilities
capabilities = DesiredCapabilities.INTERNETEXPLORER
#delete platform and version keys
capabilities.pop("platform", None)
capabilities.pop("version", None)
#start an instance of IE
driver = webdriver.Ie(executable_path="C:\\your\\path\\to\\IEDriverServer.exe", capabilities=capabilities)
driver.get("https://www.google.com/")
My guess, so far, is that this error happens because w3c_caps are passed as the only right capabilities. You can see that in the Traceback:
response = self.execute(Command.NEW_SESSION, parameters)
when you click on it you will see that:
w3c_caps["alwaysMatch"].update(capabilities)
As you can see here _W3C_CAPABILITY_NAMES hold different values than the ones we are passing.
We are passing "WINDOWS" as "platform", while _W3C_CAPABILITY_NAMES has "platformName" and accepts only small caps. Same goes for "version" key.
So we were adding capabilities that are not recognized.
This workaround is by no means perfect, and I was able to start IE in selenium java without deleting some of the capabilities.
EDIT: Another solution can be found here in Grimlek comment, which essentially says that you should delete "capabilities": w3c_caps from start_session(self, capabilities, browser_profile=None) (from remote\webdriver.py). Code looks like this:
w3c_caps["alwaysMatch"].update(capabilities)
parameters = {"capabilities": w3c_caps,
"desiredCapabilities": capabilities}
Then you would not need to delete keys from capabilities.
ANOTHER EDIT: I have just updated my selenium-python from 3.4.3 to 3.5.0 and there's no longer need for messing with capabilities.

Categories

Resources