Home > Back-end >  WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist

Time:04-15

It is an old question but I don't find answer to my situation.

my code is a simple test code

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
 
url="http://news.163.com/"
chrome_options = Options()
# specify headless mode
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('–headless')
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("disable-infobars")
browser = webdriver.Chrome(options=chrome_options)
browser.set_page_load_timeout(300)
browser.set_script_timeout(300)
browser.get(url)
title=browser.find_elements_by_xpath('//div[@id="js_top_news"]/h2/a')
print(title[0].get_attribute('innerHTML'))
browser.quit()
driver.quit()

And I have added all the argument in options. And ps -aux |grep google-chrome and kill all the process in my wsl. Google Chrome 100.0.4896.88 with chrome-driver 100.0.4896.60 and they are in the same dir added in environment path. Its two o 'clock in the morning I really appreciate anybody who help me out

CodePudding user response:

I would try using the updated version of the driver. Otherwise upgrade or downgrade your version to see if any of those work. This error is generally due to incompatibility

CodePudding user response:

Google Chrome 100.0.4896.88 and chrome-driver 100.0.4896.60 are perfectly in sync.

However as per the documentation:

A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. Please configure your environment to run Chrome as a regular user instead.


Solution

Remove the following arguments:

  • --no-sandbox
  • --disable-gpu
  • --disable-dev-shm-usage
  • disable-infobars

and execute your tests as non-root user (non-administrator) user.

CodePudding user response:

In wsl1, people can not use a linux version of chrome. so just use windows version chrome.exe and chromdriver.exe. And my problem solved by simply mv chromdriver.exe chromdriver,because selenium can only identify chromdriver without '.exe'

  • Related