selenium.common.exceptions.WebDriverException: Message: - python-3.x

I am running following simple python3 script on Windows11:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
options = webdriver.ChromeOptions()
options.binary_location = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
service = Service(executable_path='C:\\ProgramFiles\\Google\\Chrome\\Application\\chromedriver.exe')
webC = webdriver.Chrome(options=options, service=service)
I am getting the flowing error:
Traceback (most recent call last):
File "E:/NNs/CrawlerStarter/selenium_test.py", line 8, in <module>
webC = webdriver.Chrome(options=options, service=service)
File "D:\Anaconda\envs\crawler\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "D:\Anaconda\envs\crawler\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 92, in __init__
super().__init__(
File "D:\Anaconda\envs\crawler\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 276, in __init__
self.start_session(capabilities, browser_profile)
File "D:\Anaconda\envs\crawler\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 369, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "D:\Anaconda\envs\crawler\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 434, in execute
self.error_handler.check_response(response)
File "D:\Anaconda\envs\crawler\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 207, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message:
Process finished with exit code 1
There is not error message to tell what's going wrong, and I have tried related solutions that could found in Google, such as setting Path in System Environment. But it's still occurred same exception. Also, I had the same problem when I switched to Firefox
Here are my versions:
python: 3.8.13
selenium: 4.4.0
google chrome: 104.0.5112.81
chromedriver: 104.0.5112.79
Thank you for answering my question!

Related

Why can't run geckodriver in selenium?

Download chromedriver and extract it.
from selenium import webdriver
driver = webdriver.Chrome(executable_path='/home/debian/Downloads/chromedriver')
It works fine.
Now to test geckodriver for firefox,my firefox version is 78.0.2 (64-bit),the latest version,i have downloaded the geckodriver-v0.26.0-linux64.tar.gz and extract it.
from selenium import webdriver
driver = webdriver.Firefox(executable_path='/home/debian/Downloads/geckodriver')
It encounter some issues:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
How to fix it?
first check if selenium are downloaded with no error and make sure that the webdriver are downloaded in the path in this code driver = webdriver.Firefox(executable_path='/home/debian/Downloads/geckodriver')
that's should fix your problem

Error using selenium python module. Trying to click a button on DocDroid website. https://www.docdroid.net/

#Function to click a button on DocDroid website
def sendpdf():
import selenium
driver=webdriver.Chrome()
driver.get('https://www.docdroid.net/')
upload_box=driver.find_element_by_id('select')
upload_box.click()
sendpdf()
if I add 'from selenium import webdriver' I get the following error:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/User/Desktop/Computer Projects/Virus/pdfsend.py", line 11, in <module>
sendpdf()
File "C:/Users/User/Desktop/Computer Projects/Virus/pdfsend.py", line 6, in sendpdf
driver=webdriver.Chrome()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
>>>
I'm for some reason getting the following error:
NameError: name 'webdriver' is not defined
packages\selenium\webdriver\chrome\webdriver.py", line 73, in init
self.service.start()
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
You need to add chromedriver in your system PATH, you can download it from here

"Unable to find a matching set of capabilities" using selenium/geckodriver for Firefox on Windows10

Versions:
geckodriver 0.26.0 (in PATH environment variable)
selenium 3.141.0
Firefox 75.0
python 3.8.2
Windows 10
When I try:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://seleniumhq.org/')
I get this:
Traceback (most recent call last):
File "C:\Users\Me\Desktop\python\FFtests.py", line 3, in <module>
driver = webdriver.Firefox()
File "C:\Users\Me\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "C:\Users\Me\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\Me\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\Me\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\Me\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: Unable to find a matching set of capabilities
When I try:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
driver = webdriver.Firefox(capabilities = cap)
driver.get('https://seleniumhq.org/')
I get this:
Traceback (most recent call last):
File "C:\Users\me\Desktop\python\FFtests.py", line 6, in <module>
driver = webdriver.Firefox(capabilities = cap)
File "C:\Users\me\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 190, in __init__
executor = ExtensionConnection("127.0.0.1", self.profile,
File "C:\Users\me\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Users\me\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 73, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "C:\Users\me\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 103, in _wait_until_connectable
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
IEDriver works fine for IE
I have Windows Visual Studio installed as https://github.com/mozilla/geckodriver/releases indicates I should.
What can I do to make this work?
This is likely an issue with FireFox version. Try updating Firefox and Selenium.
Update Firefox
Update Selenium
Reinstall/update Geckodriver
See here for more solutions.

Windows10 ubuntu bash: chromedriver can not initiate Chrome?

I am trying to use chromeriver to fetch some url. But It is not working.
This is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
#from langdetect import detect, DetectorFactory
chrome_options = Options()
# chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
# chrome_options.add_argument('--remote-debugging-port=9222')
driver = webdriver.Chrome(
chrome_options=chrome_options)
which gives me this error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
It apparently can't start the Chrome.
If I uncomment this line in the code:
chrome_options.add_argument('--headless')
It stops working and I have to break it with ctrl + C
which shows this traceback:
Traceback (most recent call last):
File "/home/payman/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 379, in _make_request
httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "crawler.py", line 14, in <module>
chrome_options=chrome_options)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/remote_connection.py", line 374, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/remote_connection.py", line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "/home/payman/.local/lib/python3.6/site-packages/urllib3/request.py", line 72, in request
**urlopen_kw)
File "/home/payman/.local/lib/python3.6/site-packages/urllib3/request.py", line 150, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "/home/payman/.local/lib/python3.6/site-packages/urllib3/poolmanager.py", line 326, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/home/payman/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/home/payman/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/usr/lib/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
KeyboardInterrupt
My chromedriver executable is stored in the this directory \usr
and so in the .bashrc I have added:
export PATH="/usr:$PATH"
I have followed the installations on this page:
How to Setup Selenium with ChromeDriver on Ubuntu 18.04 & 16.04

Trying to connect to tor with python3

I have been trying to connect to tor with python on Mac. If it helps, I have python3 and Mac Mojave. My code is:
import stem.process
from stem import Signal
from stem.control import Controller
from splinter import Browser
proxyIP = "127.0.0.1"
proxyPort = 9150
proxy_settings = {"network.proxy.type":1,
"network.proxy.ssl": proxyIP,
"network.proxy.ssl_port": proxyPort,
"network.proxy.socks": proxyIP,
"network.proxy.socks_port": proxyPort,
"network.proxy.socks_remote_dns": True,
"network.proxy.ftp": proxyIP,
"network.proxy.ftp_port": proxyPort
}
browser = Browser('firefox', profile_preferences=proxy_settings)
browser.visit("http://www.icanhazip.com")
However, whenever I run it, an error occurs:
Traceback (most recent call last):
File "test.py", line 27, in <module>
browser = Browser('firefox', profile_preferences=proxy_settings)
File "/usr/local/lib/python3.6/site-packages/splinter/browser.py", line 64, in Browser
return driver(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/splinter/driver/webdriver/firefox.py", line 78, in __init__
**kwargs
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
Any help would be appreciated. Regards, Tyler
I don't know your selenium version and geckodriver version,so what i can answer is upgrade them.
pip install -U selenium
download latest version geckodriver from here

Resources