Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Selenium WebDriverException #10341

Closed
fconil opened this issue Feb 8, 2022 · 7 comments
Closed

[🐛 Bug]: Selenium WebDriverException #10341

fconil opened this issue Feb 8, 2022 · 7 comments

Comments

@fconil
Copy link

fconil commented Feb 8, 2022

What happened?

Hi,

I can not start a session on Ubuntu 20.04 with Chrome, I get an exception : WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist.

I am using Python 3.8.10, I work inside a virtualenv : .venv

The chrome driver is installed in .venv/bin which comes first in the $PATH.

I saw https://stackoverflow.com/a/50642913/481719, but I tried several options without success.

Chrome binaries are installed by apt / snap in /snap/bin and belong to root. This is not a problem for Firefox, I admit I am confused by this thread. I did not found how to "run Chrome as a regular user", I may be missing something.

Any advice would be welcome.

Regards

How can we reproduce the issue?

import os

import selenium
import selenium.webdriver
from selenium.webdriver.chrome.service import Service as ChromeService

chromepath = f"{os.getcwd()}/.venv/bin/chromedriver"

service = ChromeService(executable_path=chromepath)
options = selenium.webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument("--disable-dev-shm-usage")
options.add_argument('--headless')
driver = selenium.webdriver.Chrome(service=service, options=options)

Relevant log output

$ python selenium-chrome.py
Traceback (most recent call last):
  File "selenium-chrome.py", line 57, in <module>
    driver = selenium.webdriver.Chrome(service=service, options=options)
  File "/.../openfoodfacts/.venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/.../openfoodfacts/.venv/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "/.../openfoodfacts/.venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 268, in __init__
    self.start_session(capabilities, browser_profile)
  File "/.../openfoodfacts/.venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 359, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/.../openfoodfacts/.venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "/.../openfoodfacts/.venv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
Stacktrace:
#0 0x562e39f79113 <unknown>
#1 0x562e39a416d8 <unknown>
#2 0x562e39a67632 <unknown>
#3 0x562e39a63bb9 <unknown>
#4 0x562e39a6019a <unknown>
#5 0x562e39a9ae0a <unknown>
#6 0x562e39a94f53 <unknown>
#7 0x562e39a6abda <unknown>
#8 0x562e39a6bca5 <unknown>
#9 0x562e39faa8dd <unknown>
#10 0x562e39fc3a9b <unknown>
#11 0x562e39fac6b5 <unknown>
#12 0x562e39fc4725 <unknown>
#13 0x562e39fa008f <unknown>
#14 0x562e39fe1188 <unknown>
#15 0x562e39fe1308 <unknown>
#16 0x562e39ffba6d <unknown>
#17 0x7f77b6cf8609 <unknown>

Operating System

Ubuntu 20.04.3

Selenium version

Python 4.1.0

What are the browser(s) and version(s) where you see this issue?

Chromium 98.0.4758.80 snap

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 98.0.4758.80

Are you using Selenium Grid?

I do not think I am using Selenium Grid

@github-actions
Copy link

github-actions bot commented Feb 8, 2022

@fconil, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@ut
Copy link

ut commented Feb 9, 2022

I can confirm this problem in a different setting: By using Capybara (on Ruby on Rails 5) with selenium-wevbdriver 4.1.0 (via the Webdrivers Gem), which returns two different errors

1.1) Failure/Error: visit root_path
       
       Net::ReadTimeout:
         Net::ReadTimeout

and

2.1) Failure/Error: visit root_path
       
       Selenium::WebDriver::Error::UnknownError:
         unknown error: DevToolsActivePort file doesn't exist
       # #0 0x55c9956d5113 <unknown>
       # #1 0x55c99519d6d8 <unknown>
       # #2 0x55c9951c3632 <unknown>
       # #3 0x55c9951bfbb9 <unknown>
       # #4 0x55c9951bc19a <unknown>
       # #5 0x55c9951f6e0a <unknown>
       # #6 0x55c9951f0f53 <unknown>
       # #7 0x55c9951c6bda <unknown>
       # #8 0x55c9951c7ca5 <unknown>
       # #9 0x55c9957068dd <unknown>
       # #10 0x55c99571fa9b <unknown>
       # #11 0x55c9957086b5 <unknown>
       # #12 0x55c995720725 <unknown>
       # #13 0x55c9956fc08f <unknown>
       # #14 0x55c99573d188 <unknown>
       # #15 0x55c99573d308 <unknown>
       # #16 0x55c995757a6d <unknown>
       # #17 0x7fda34a0f609 <unknown>
       # /home/osboxes/.rvm/gems/ruby-2.7.5/gems/selenium-webdriver-4.1.0/lib/selenium/webdriver/remote/response.rb:56:in `assert_ok'

Please note:

Webdrivers Current version is ChromeDriver 98.0.4758.80 

@fconil
Copy link
Author

fconil commented Feb 9, 2022

I made some further tests but I won't have time to do much more.

I user Chromium browser, not Chrome.

Even if I did an apt install chromium, it was installed with snap. So binaries are in /snap/bin/ and I noticed there was a chromium.chromedriver in the folder.

The 2 binaries return the same version information, but have different hash:

$ chromedriver --version
ChromeDriver 98.0.4758.80 (7f0488e8ba0d8e019187c6325a16c29d9b7f4989-refs/branch-heads/4758@{#972})

$ chromium.chromedriver --version
ChromeDriver 98.0.4758.80 (7f0488e8ba0d8e019187c6325a16c29d9b7f4989-refs/branch-heads/4758@{#972})

$ md5sum /snap/bin/chromium.chromedriver .venv/bin/chromedriver 
0211d8cc2aa0d28eb2eb5394b4e29a5d  /snap/bin/chromium.chromedriver
45b7ee2d481090eed757eb41f2ca5240  .venv/bin/chromedriver

If I specify a path to the "snap chromedriver", it works without any weird option, and I get no DevToolsActivePort error. It seems to be the solution but it would be nice if it was used by default if no executable_path is given.

import selenium.webdriver
from selenium.webdriver.chrome.service import Service as ChromeService

service = ChromeService(executable_path="/snap/bin/chromium.chromedriver")
options = selenium.webdriver.ChromeOptions()

# Seems to work
options.headless = True

driver = selenium.webdriver.Chrome(service=service, options=options)

driver.get("https://www.selenium.dev/")
# Print page name
print(driver.title)

# Print information about the chromedriver
print(f"{driver.service.path=}")

driver.quit()

I have been able to use the downloaded chromedriver that is in .venv/bin with --remote-debugging-port=9222 option. I found this option on https://stackoverflow.com/a/56638103/481719 but I am not sure that this is a solution. If I try to specify the exact path, it does note work anymore

import selenium.webdriver
from selenium.webdriver.chrome.service import Service as ChromeService

options = selenium.webdriver.ChromeOptions()

options.headless = True

# Solving problem : https://stackoverflow.com/a/56638103/481719
options.add_argument('--remote-debugging-port=9222')

driver = selenium.webdriver.Chrome(options=options)

driver.get("https://www.selenium.dev/")
# Print page name
print(driver.title)

# Print information about the chromedriver
print(f"{driver.service.path=}")

driver.quit()

I found some better explanations about DevToolsActivePort on https://stackoverflow.com/a/62545820/481719

If I had more time, I could try to dig in the chromedriver source code documentation : https://chromium.googlesource.com/chromium/src/+/refs/heads/main/chrome/test/chromedriver#

I saw some recent bug report on DevToolsActivePort file doesn't exist : https://bugs.chromium.org/p/chromedriver/issues/list?q=DevToolsActivePort%20file%20doesn%27t%20exist&can=2

Hope it will help

@titusfortner
Copy link
Member

If I specify a path to the "snap chromedriver", it works without any weird option, and I get no DevToolsActivePort error. It seems to be the solution but it would be nice if it was used by default if no executable_path is given.

This means it is working for you?

If a driver location is not specified, Selenium finds the first available driver in PATH. That driver finds the first available Chrome instance on the machine.

If those don't match what you want to use, you will always need to specify the ones you need.

@fconil
Copy link
Author

fconil commented Feb 10, 2022

If I specify a path to the "snap chromedriver", it works without any weird option, and I get no DevToolsActivePort error. It seems to be the solution but it would be nice if it was used by default if no executable_path is given.

This means it is working for you?

Yes, it works but I have had the problem with a library that uses Selenium and where I can not specify an executable_path.

chromium.chromedriver is installed with Chromium and it is in PATH. I imagine selenium.webdriver.Chrome() looks for a driver named chromedriver. So I found a workaround by creating a symbolic link :

# In /snap/bin
$ sudo ln -s chromium.chromedriver chromedriver

Thus it works without specifying an executable_path.

Though I have this solution, I would also like to understand why I had a DevToolsActivePort file doesn't exist error with the downloaded chromedriver placed in .venv/bin.

@titusfortner
Copy link
Member

As I said above, the libraries do their best to guess what you want, and if they guess incorrectly, you'll have to specify.

Most likely DevToolsActivePort issue is with permissions between the executing user and the default located driver for some reason.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants