Is Chromedriver_autoinstaller still working? - python

I would like to run chromedriver_autoinstaller. I follow example here: https://pypi.org/project/chromedriver-autoinstaller/
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install() # Check if the current version of chromedriver exists
# and if it doesn't exist, download it automatically,
# then add chromedriver to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
But I got an error:
Traceback (most recent call last):
File "/usr/lib/python3.8/code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 9, in <module>
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/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: DevToolsActivePort file doesn't exist
What does it mean? Is this package still working?

This error message...
org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.
Execute your test as a regular user.
References
You can find a couple of detailed discussions in:
WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu
Tests fail immediately with unknown error: DevToolsActivePort file doesn't exist when running Selenium grid through systemd

Related

Problems when running selenium with chromedriver_autoinstaller in Python

I have a following problem. I would like to run chromium on my Ubuntu using chromedriver_autoinstaller. My code is:
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install() # Check if the current version of chromedriver exists
# and if it doesn't exist, download it automatically,
# then add chromedriver to path
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = options)
driver.get("http://www.python.org")
But desired url http://www.python.org does not open, I just see data:, in the browser:
I tried to add some options, but it did not help:
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install() # Check if the current version of chromedriver exists
# and if it doesn't exist, download it automatically,
# then add chromedriver to path
options = webdriver.ChromeOptions()
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument('--remote-debugging-port=9222')
driver = webdriver.Chrome(options = options)
driver.get("http://www.python.org")
Full traceback:
Traceback (most recent call last):
File "/usr/lib/python3.8/code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 14, in <module>
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/vojtam/Desktop/greads_scrape/venv/lib/python3.8/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: DevToolsActivePort file doesn't exist
Do you know, what is the problem here?
I found this questions, but it did not help me:
WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu
Tests fail immediately with unknown error: DevToolsActivePort file doesn't exist when running Selenium grid through systemd
The problem was that Docker requires chrome_options.add_argument("--headless") when running chrome in selenium

Selenium WebDriverException issue - python, cannot start browser both in Chrome/Firefox

I have the following script that makes use of selenium for authentication process.
I'm on Ubuntu 20.04 LTS, the computer was reformatted in the past few days, the same script worked before, from reading other threads I suspect that this has to do something with the root user/privileges.
I've tried both Firefox (geckodriver) and Chrome (chromedriver), here's what I did:
Chrome:
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
import chromedriver_autoinstaller
chromedriver_path = chromedriver_autoinstaller.install()
browser = Chrome(executable_path=chromedriver_path)
The error:
Traceback (most recent call last):
File "/home/or/Desktop/Tutorials/Selenium/chrome.py", line 7, in <module>
browser = Chrome(executable_path=chromedriver_path)
File "/home/or/anaconda3/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/home/or/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/or/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/or/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/or/anaconda3/lib/python3.8/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: 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.)
Firefox:
from selenium.webdriver import Firefox
import geckodriver_autoinstaller
geckodriver_path = geckodriver_autoinstaller.install()
browser = Firefox(executable_path=geckodriver_path)
The error:
Traceback (most recent call last):
File "/home/or/Desktop/Tutorials/Selenium/firefox.py", line 7, in <module>
browser = Firefox(executable_path=geckodriver_path)
File "/home/or/anaconda3/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/home/or/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/or/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/or/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/or/anaconda3/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
Also in the geckodriver.log:
1620916609933 mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileVlJnBC"
Error: no DISPLAY environment variable specified
I've made sure that my chrome is installed in the default folder, tried to use options such as --no-sandbox, tried to set binary location to where chrome is, did not work.
I've installed chrome in its default path on Linux.
I've tried with the --no sandbox option
I've tried specified the binary path by setting `options.binary_path = '/path/to/google-chrome'
I've installed Xvfb on my machine
I've tried downloading the chromedriver and geckodriver manually and adding them to the path (after placing in /usr/local/...)

Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided

I am trying to get back into using Python Webdriver. I have here the code
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\Users\Cody\Downloads\geckodriver.exe')
driver.get('http://inventwithpython.com')
This causes:
C:\Users\Cody\Projects>python accounting.py
Traceback (most recent call last):
File "accounting.py", line 4, in <module>
driver = webdriver.Firefox(executable_path=r'C:\Users\Cody\Downloads\geckodriver.exe')
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
If I try:
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\Users\Cody\Downloads')
driver.get('http://inventwithpython.com')
I get
C:\Users\Cody\Projects>python accounting.py
Traceback (most recent call last):
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "accounting.py", line 4, in <module>
driver = webdriver.Firefox(executable_path=r'C:\Users\Cody\Downloads')
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\common\service.py", line 86, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'Downloads' executable may have wrong permissions.
Geckodriver.exe is sitting right there in the downloads folder.
This error message...
selenium.common.exceptions.SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
...implies that the GeckoDriver was unable to locate the firefox executable while trying to initiate/spawn a new Browsing Context i.e. Firefox Browser session.
Reason
The two primary reasons for this error are as follows:
Firefox isn't installed within your system.
Firefox isn't installed at the default location within your system.
Solution
The possible solutions are:
If Firefox isn't installed in your system, you need to install it before executing your tests.
If Firefox is installed at a customized location, you need to pass the absolute path of the firefox binary as follows through an Options() instance:
from selenium import webdriver
options = webdriver.FirefoxOptions()
options.binary_location = r"C:/location/to/Firefox/Binary/firefox.exe"
driver = webdriver.Firefox(executable_path=r'C:\Users\Cody\Downloads\geckodriver.exe', options=options)
driver.get('http://inventwithpython.com/')
References
You can find a couple of relevant detailed discussion in:
SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary'
InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided using GeckoDriver

selenium and google chrome driver wont run on linux python [duplicate]

This question already has answers here:
Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed
(22 answers)
Closed 2 years ago.
I'm unable to get chromium to run when i put my code in theoretically it looks like it should work i even followed tutorials but i keep getting the same error message. This is the code that i put:
from selenium import webdriver
#chromedriver varible with exact location to where its saved
chromedriver = "/home/jackmiller/Downloads/chromedriver"
#varible of drive to run open up the chrome driver which is located
#on my machine as chromedriver varible chromedriver
driver = webdriver.Chrome(chromedriver)
#open this website
driver.get('https://youtube.com')
and when i run the code in terminal this is what it returns:
Traceback (most recent call last):
File "automation.py", line 8, in <module>
driver = webdriver.Chrome(chromedriver)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
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's not opening chromium at all
Have you tried: options.add_argument("--remote-debugging-port=9222")
From this bug report: https://github.com/SeleniumHQ/selenium/issues/6049
A workaround is to specify the remote debugging port as an argument for your ChromeOptions, something like: options.add_argument("--remote-debugging-port=9222"), and if you're running in a container make the driver headless like so options.headless = True, otherwise use something like pyvirtualdisplay for screenshots.
Are you tried make chromedriverfile executable?
sudo chmod a+x chromedriver

Unable to Open Chrome Webdriver in Windows 10 [duplicate]

This question already has answers here:
SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81
(37 answers)
Closed 2 years ago.
I want to use chrome webdriver with python and selenium library; however, I'm having problems opening webdriver in python console. It is finding the path and it opens what it seems to be a browser, also it starts a service listening on port #### but when I do
driver.get('http://www.google.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'driver' is not defined
it doesn't work... here's the error I'm getting when I open a website
here's the output of opening webdriver
driver = webdriver.Chrome('C:\chromedriver\chromedriver.exe')
DevTools listening on ws://127.0.0.1:52968/devtools/browser/b7b88ebb-e9e1-4726-9d4e-4e3f13990a0a Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\George\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\George\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\George\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\George\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\George\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: This version of ChromeDriver only supports Chrome version 81
You need your chromedriver.exe to match your current chrome browser's version. To check your chrome version go into your chrome settings and select the about chrome tab. You can find your chrome version there. Then download the chromedriver from here that matches your version. Update the path in your code to this driver and it should work.

Categories