WebDriverError: 断开连接:无法连接到渲染器

34

元数据 -

操作系统: OSX 10.12.6 (16G29)

~./node_modules/chromedriver/bin/chromedriver  -v
ChromeDriver 2.32.498537 (cb2f855cbc7b82e20387eaf9a43f6b99b6105061)

~ $ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7/Contents/Home

~ $ node -v
v6.11.2

浏览器:

Chrome 版本 62.0.3202.62 (官方版本) (64 位)

浏览器版本:

62.0.3202.62 (官方版本) (64 位)

期望行为 -

Chrome 浏览器会启动,脚本会一直执行到结束

实际行为 -

浏览器已经启动,但脚本立即崩溃。

代码:

> ucb-client@2.97.3 selenium-local /Users/Georgios/Development/rocket-internet/ucb-client
> node test/automation-tests/testcases/happy-path/Local_Guest_Cash.js

/Users/Georgios/Development/rocket-internet/ucb-client/node_modules/selenium-webdriver/lib/promise.js:2634
        throw error;
        ^

WebDriverError: disconnected: unable to connect to renderer
  (Session info: chrome=62.0.3202.62)
  (Driver info: chromedriver=2.32.498537 (cb2f855cbc7b82e20387eaf9a43f6b99b6105061),platform=Mac OS X 10.12.6 x86_64)
    at WebDriverError (/Users/Georgios/Development/rocket-internet/ucb-client/node_modules/selenium-webdriver/lib/error.js:27:5)
    at Object.checkLegacyResponse (/Users/Georgios/Development/rocket-internet/ucb-client/node_modules/selenium-webdriver/lib/error.js:529:15)
    at parseHttpResponse (/Users/Georgios/Development/rocket-internet/ucb-client/node_modules/selenium-webdriver/lib/http.js:509:13)
    at doSend.then.response (/Users/Georgios/Development/rocket-internet/ucb-client/node_modules/selenium-webdriver/lib/http.js:441:30)
    at process._tickCallback (internal/process/next_tick.js:109:7)
From: Task: WebDriver.manage().window().setSize(1280, 720)
    at thenableWebDriverProxy.schedule (/Users/Georgios/Development/rocket-internet/ucb-client/node_modules/selenium-webdriver/lib/webdriver.js:807:17)
    at Window.setSize (/Users/Georgios/Development/rocket-internet/ucb-client/node_modules/selenium-webdriver/lib/webdriver.js:1677:25)
    at Object.<anonymous> (/Users/Georgios/Development/rocket-internet/ucb-client/test/automation-tests/testcases/happy-path/Local_Guest_Cash.js:8:26)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
Actual script (beginning)

require('chromedriver');
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder().forBrowser('chrome').build();
var timeout = 15000;
5个回答

43

我遇到了类似的错误,但版本是相匹配的:我使用的是Chrome 65和驱动程序版本2.38。

我花了很长时间来尝试理解这个问题。最后,发现是由于空的/etc/hosts文件引起的。显然,Chrome通过localhost进行通信,如果在/etc/hosts中缺少这样的条目,它就会崩溃。

因此,请确保它有像这样的条目:

127.0.0.1 localhost


11
我遇到了使用 Mac OS X 10.13.6,Selenium 3.13.0,Chromedriver 2.41 和 Chrome 67 的问题。在 /etc/hosts 文件中添加以下一行内容:127.0.0.1 localhost loopback问题就得到了解决。 - Todd O'Bryan
3
我花了几个晚上的时间研究这个问题,很多解决方案都要求确保您的版本都是最新的/同步的:selenium、chrome、chromedriver...如果您的版本全部同步并更新,则需要执行以下操作。通过编辑/etc/hosts文件并添加TOB的代码注释,我成功地解决了这个问题。 - Krusaderjake
6
你是怎么找到那的?天哪,我浪费了一整天时间。 - Jeff Lowery
1
这解决了我的问题。我检查了所有版本,都没问题,但现在我想起来,有一天我把“localhost”条目改成了另一个主机。更改为“127.0.0.1 localhost”就可以了。我浪费了两天的时间去弄清楚这个问题。谢谢! - Bhavesh G
1
根据上面的评论,这也为我节省了不少时间。 - Anirudh
显示剩余2条评论

32

您正在使用的是chromedriver 2.32,而在发行说明中写到支持 Chrome v59-61

您所使用的浏览器为:

Chrome Version 62.0.3202.62 (Official Build) (64-bit) 

因此,从 ChromeDriver 中,您应该使用2.33版本。


5
没错!从 https://chromedriver.storage.googleapis.com/index.html?path=2.33/ 下载最新版本,问题就会消失。 - Krzysztof Walczewski
1
只是需要注意的是,这并不是一个干净利落的过程,有些东西(向后兼容性方面)还没有解决,但目前看来这些问题都比较小(主要是窗口位置,本来也没什么用)。 - NSGaga-mostly-inactive
1
非常感谢,这解决了我的问题。我运行的是旧版本的chromedriver和Chrome 62。 - C.B.
请注意,这是 https://bugs.chromium.org/p/chromedriver/issues/detail?id=1918 的一个具体实例。 - Tom Parker-Shemilt
在 Chrome 65 和 chromedriver v.2.31(然后更新到v.2.36)上运行 npm install -g chromedriver 解决了我的问题! - montrealist
我正在使用最新的Chrome浏览器80版本,但对我来说它仍然显示相同的错误消息... - Rajesh Om

1
这是对@davide-patti的解决方案的一个补充。:) 当我遇到unable to connect to renderer错误时,我从@davide-patti那里得知我正在使用较旧版本的chromedriver,即v2.32。 但是我无法使用homebrew升级我的chromedriver,因为我持续收到:No available formula with the name "chromedriver"
这篇文章帮助我很多,让我升级到了v2.33+。 关于:错误:“No available formula with the name “chromedriver”” https://github.com/Homebrew/brew/issues/4089

1
由于页面加载时间过长导致了这个问题,你需要在你的脚本中添加额外的代码行。
System.setProperty("webdriver.chrome.driver","E:\\selenium\\chromedriver_2.41\\chromedriver.exe");
//mention the below chrome option to solve timeout exception issue
ChromeOptions options = new ChromeOptions();
options.setPageLoadStrategy(PageLoadStrategy.NONE);
// Instantiate the chrome driver
driver = new ChromeDriver(options);

在 AWS Lambda 中运行 headful Chrome 时出现了错误。设置页面加载策略解决了该错误。谢谢。 - jbaranski

0

这是因为驱动程序没有关闭,你尝试再次运行。
尝试重新启动或更改端口ID。
options.addArguments("--remote-debugging-port=9230")
你可以更改这个端口。
谢谢


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接