0

So I'm working on a script that scrapes some data from a dynamic webpage and commits it to my database tables. For this, I've used Selenium in Python. It all worked perfectly fine until I restarted my system. Now chrome only works in headless mode and when I comment out that option so that I get to see an actual window of the chrome browser, I get this error

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.)

snapshot of the code

Solutions tried:

  • cross-checked the path of my chrome-binaries and it is valid
  • changed the order of adding options
  • uninstalled chrome and reinstalled it again
  • deleted the chromedriver and downloaded it again
  • restarted my system twice
  • googled the error and tried the solutions

EDIT: I have already tried adding the --no-sandbox option before commenting it out here as shown in the snapshot

One thing I would want to mention is that my root space is quite less and only 340 mb of free space is left. Does that affect?

1 Answers1

0

To see an actual window of the chrome browser removing the argument -headless is perfect.

However, I would suggest to remove all the unwanted options and execute your test with the minimal lines of code as follows:

from selenium import webdriver from selenium.webdriver.chrome.options import Options

chrome_options = webdriver.ChromeOptions() 
chrome_options.add_argument('start-maximized')
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=chrome_options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get("http://google.com/")

In case you see the error as:

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.)

You may need to add the argument --no-sandbox.

So the solution is to add back the argument:

chrome_options.addArguments("--no-sandbox");
chrome_options.addArguments("--disable-dev-shm-usage");

You can find a detailed discussion in WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser


Additional considerations

Ensure that:

  • Selenium is upgraded to current levels Version 3.141.59.
  • ChromeDriver is updated to current ChromeDriver v83.0 level.
  • Chrome is updated to current Chrome Version 83.0 level. (as per ChromeDriver v83.0 release notes)
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test as non-root user.

Reference

You can find a detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352