我试图用一个URL启动chrome浏览器,浏览器启动后,它什么也不做。

1分钟后我看到如下错误:

Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
  (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

我的配置:

Chrome浏览器:66 ChromeBrowser: 2.39.56

又及,在Firefox中一切都很好


当前回答

没有解决方法对我有效。但这里有一个变通办法:

maxcounter=5
for counter in range(maxcounter):
    try:           
        driver = webdriver.Chrome(chrome_options=options,
                          service_log_path=logfile,
                          service_args=["--verbose", "--log-path=%s" % logfile])
        break
    except WebDriverException as e:
        print("RETRYING INITIALIZATION OF WEBDRIVER! Error: %s" % str(e))
        time.sleep(10)
        if counter==maxcounter-1:
            raise WebDriverException("Maximum number of selenium-firefox-webdriver-retries exceeded.")

其他回答

我的端口号错了。检查启动Selenium服务器时的端口号是否与脚本中的端口号相同。

你可以得到这个错误简单地传递坏的参数Chrome。例如,如果我将“headless”作为参数传递给c# ChromeDriver,它会很好地启动。如果我犯了一个错误,使用了错误的语法,“——headless”,我得到DevToolsActivePort文件不存在错误。

对于Ubuntu 20,它确实帮助我使用我的系统铬驱动程序,而不是下载的那个:

# chromium which
/snap/bin/chromium

driver = webdriver.Chrome('/snap/bin/chromium.chromedriver',
                          options=chrome_options)

对于下载的web驱动程序来说,它看起来需要远程调试端口——remote-debugging-port=9222来设置,就像其中一个答案(由Soheil Pourbafrani):

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome('<path_to>/chromedriver', options=chrome_options)

核心的答案 正确的解决方案:不使用root用户运行Chrome二进制 更多细节请参考另一个帖子的回答:未知错误:DevToolsActivePort文件不存在

我被这个问题困扰了很长一段时间,最后通过添加一个额外的选项来解决它:

options.addArguments(”——crash-dumps-dir = / tmp”)