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
Related
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
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/...)
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)
unknown error: DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu
(15 answers)
Closed 3 years ago.
I am trying to run some scripts with seleniun and am getting this error:
Traceback (most recent call last):
File "/var/www/pyscripts/qualidental.py", line 12, in <module>
driver = webdriver.Chrome(BASE_WEB_DRIVER, options=chrome_options)
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/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.)
Details, I'm doing this on a text mode server only (debian 8)
My code:
BASE_WEB_DRIVER = "/scripts/chromium-browser/chromedriver"
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--incognito')
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(BASE_WEB_DRIVER, options=chrome_options)
My version Chrome: Google Chrome 78.0.3904.108
My version driver: ChromeDriver 78.0.3904.105 (60e2d8774a8151efa6a00b1f358371b1e0e07ee2-refs/branch-heads/3904#{#877})
so today I went to run a program I made in python 3, but it kept crashing when it tried to open chromium. I haven't updated python or the chromedriver.exe so it was strange why it didn't work.
Current version of chrome driver I have installed: 74.0.3729.6
I have tried the following things but it didn't work:
Updating to the latest version of the chrome driver (v77.0.3865.10)
Downgrading to v73 of the chrome driver
Nothing has worked. Could someone please assist me.
I made this test program with just it launching the chrome browser:
main.py
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--window-size=1920,1080")
driver = webdriver.Chrome(options=options)
driver.create_options()
driver.maximize_window()
crash message:
DevTools listening on ws://127.0.0.1:50904/devtools/browser/c1dc7138-e0cb-4ce4-a
561-56588f5ffd26
Traceback (most recent call last):
File "main.py", line 5, in <module>
driver = webdriver.Chrome(options=options)
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37-32\lib\site-packages
\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37-32\lib\site-packages
\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37-32\lib\site-packages
\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37-32\lib\site-packages
\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\myUser\AppData\Local\Programs\Python\Python37-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 crea
ted: This version of ChromeDriver only supports Chrome version 74
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57
e9-refs/branch-heads/3729#{#29}),platform=Windows NT 6.3.9600 x86_64)
The version of both Chrome (or Chromium) and Chromedriver must coincide.
As you can see in the error, your current Chromedriver only works with Chromium version 74.
Check the version of you Chromium and install the corresponding version of Chromedriver. To do this you can run the following command in a terminal.
apt-cache policy chromium
I'm trying to run a scraper using Selenium driver
My py file is (just start)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
# Set the url we want
<and so on>
However I get the following error:
Traceback (most recent call last):
File "main.py", line 37, in <module>
driver = webdriver.Chrome(chrome_options=options)
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_respons
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 has crashed.)
(Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 4.4.0-140-generic
Searching for this error, it seems as if its incompatibility in ChromeDriver and Google-Chrome and Selenium however my Selenium version is 3.141.0, my chrome version is 72.0.3626.119 and my ChromeDriver is 2.46.
So they are all latest and they all seem compatible.
Any ideas what wrong?
I've ran into this error on Ubuntu 18.04 and it could be one of several things that's causing Chrome to crash. Try setting these flags:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--headless")
driver = webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=options)
The --headless flag ensures that Chrome starts in headless mode as I assume you don't have a desktop running on your Ubuntu. the --no-sandbox flag turns off the sandboxing in Linux that sometimes causes problems at the start.