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
CodePudding user response:
The problem was that Docker requires chrome_options.add_argument("--headless")
when running chrome in selenium