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


当前回答

我在与jenkins服务器集成时也遇到了这个问题,我使用了jenkin工作的根用户,当我将用户更改为其他用户时,这个问题得到了解决。我不确定为什么根用户会出现这个错误。

谷歌Chrome浏览器版本71.0 ChromeDriver版本2.45 CentOS7版本1.153

其他回答

在我的情况下,当我改变google-chrome和chromedriver版本时,错误被修复了:)

#google-chrome version
[root@localhost ~]# /usr/bin/google-chrome --version
Google Chrome 83.0.4103.106 

#chromedriver version
[root@localhost ~]# /usr/local/bin/chromedriver -v
ChromeDriver 83.0.4103.14 (be04594a2b8411758b860104bc0a1033417178be-refs/branch-heads/4103@{#119})

Ps:硒版本为3.9.1

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

我在python中遇到了同样的问题。以上这些都有帮助。这是我在python中使用的

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/path/to/your_chrome_driver_dir/chromedriver',chrome_options=chrome_options)

以我为例,在以下环境中:

Windows 10 Python 3.7.5 谷歌Chrome 80版本及对应的ChromeDriver路径为“C:\Windows” 硒3.141.0

我需要将参数——no-sandbox和——remote-debug -port=9222添加到ChromeOptions对象中,并以管理员用户身份运行Powershell/cmd来运行代码。

下面是相关的代码段:

options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('--disable-infobars')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')
options.add_argument('--remote-debugging-port=9222')
driver = webdriver.Chrome(options=options)

我有同样的问题,但在我的情况下,chrome之前安装在用户临时文件夹,之后被重新安装到程序文件。所以这里提供的任何解决方案都帮不了我。但是如果提供了chrome.exe的路径就可以了:

chromeOptions.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");

我希望这能帮助到一些人=)