我试图用一个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中一切都很好


当前回答

老问题,但类似的问题几乎把我逼疯了,所以分享我的解决方案。其他的建议都不能解决我的问题。

当我将Docker镜像Chrome从旧版本更新到Chrome 86时,我得到了这个错误。我的设置是不相同的,但我们实例化Chrome通过一个硒webdriver。

解决方案是将选项传递为goog:chromeOptions哈希而不是chromeOptions哈希。我真的不知道这是一个硒,Chrome, Chromedriver,或其他更新,但也许某些可怜的灵魂会在未来的这个答案中找到安慰。

其他回答

我在Ubuntu 20和Python Selenium上遇到了这个问题,我首先单独下载了chromedriver,然后使用sudo apt install chromium-browser,尽管它们是同一个版本,但这种情况一直发生。

我的修复是使用提供的chrome驱动程序,附带的回购包位于

/snap/bin/chromium.chromedriver

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

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

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

日期9/16/2021

在docker托管的ubuntu容器中使用python在本地运行chrome和selenium,一切都很好。当试图运行从Jenkins上面的错误返回WebDriverException:未知错误:DevToolsActivePort

环境:

-Ubuntu21.04在docker容器内,支持RDP访问。

chrome版本:93

解决方案: 在启动浏览器的python文件中,我必须使用以下行设置DISPLAY环境变量:

import os

os.environ['DISPLAY'] = ':10.0'
#DISPLAY_VAR = os.environ.get('DISPLAY')
#print("DISPLAY_VAR:", DISPLAY_VAR)

我通过安装yum -y install gtk3-devel gtk3-dev -docs”来解决这个问题,它可以正常工作

我的工作环境是:

Selenium Version 3.12.0
ChromeDriver Version v2.40
Chrome 68 level

之前:

后:

我遇到了同样的问题,在我的情况下,Linux系统中有两个不同的常见用户userera和userB。 userA第一次运行selinium程序成功启动chrome浏览器,当到达userB时,出现DevToolsActivePort文件不存在的错误。

我尝试了——remote-debug -port=9222选项,但它导致了一个新的异常: selenium.common.exceptions.WebDriverException: Message: chrome不可达

I run google-chome目录,看到以下错误: mkdir /tmp/Crashpad/new: Permission denied (13)

我搜索了这个问题,得到了这个: https://johncylee.github.io/2022/05/14/chrome-headless-%E6%A8%A1%E5%BC%8F%E4%B8%8B-devtoolsactiveport-file-doesn-t-exist-%E5%95%8F%E9%A1%8C/

chrome_options.add_argument(f"--crash-dumps-dir={os.path.expanduser('~/tmp/Crashpad')}")

感谢@johncylee。