D
D
Dmitry Prilepsky2022-01-23 22:48:50
Python
Dmitry Prilepsky, 2022-01-23 22:48:50

How to run chromium via selenium-python?

I want to run selenium through chromium. I wrote such 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 correct version of the chromodriver is in usr/bin. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2022-02-01
kuzmin @sergueik

the reason in snap
error is known
DevToolsActivePort file doesn't exist is caused when chrome is unable to find its reference in scoped_dirXXXXX folder.
two exits
1 . install just as an application and everything will go
2. add two options

homedir = getenv('HOME')
options.add_argument('--user-data-dir="{}"'.format(homedir))
options.add_argument('--remote-debugging-port=9222')

- if you don't like it HOME, correct it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question