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.)
Solutions tried:
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?
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
Ensure that:
@Test
as non-root user.You can find a detailed discussion in:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.