Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist with chromium browser and Selenium Python

I want to run selenium through chromium. I wrote this code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--disable-gpu")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
options.binary_location = "/snap/bin/chromium"
driver = webdriver.Chrome(chrome_options=options)

But this code throws an error:

selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
Stacktrace:
#0 0x55efd7355a23 <unknown>
#1 0x55efd6e20e18 <unknown>
#2 0x55efd6e46e12 <unknown>

The chromedriver of the correct version is in usr/bin. What am I doing wrong?

like image 258
Dima Avatar asked Jun 07 '26 09:06

Dima


2 Answers

This is because you have specified --user-data-dir and maybe a --profile-directory, and there is already a running Chrome instance which would have created a DevToolsActivePort in your specified user data dir. Thus selenium will be unable to spawn a new browser instance.

My solution is to copy the Default and Profile 1 folders (which are the two profiles I used in my case) under %LOCALAPPDATA%\Microsoft\Edge\User Data\ to my newly created D:\user_data, and specify --user-data-dir to be D:\user_data. This way I have a copy of user data for selenium only.

Hope this will solve your problem.

like image 152
user9818 Avatar answered Jun 08 '26 23:06

user9818


I solved the problem by reinstalling chromium through apt sudo apt install chromium-browser (before that it was installed through snap). My working code looks like this

options = Options()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
if headless:
options.add_argument('--headless')
options.binary_location = "/usr/bin/chromium-browser"
self.driver = webdriver.Chrome(options=options)
like image 22
Dima Avatar answered Jun 08 '26 23:06

Dima



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!