gpt4 book ai didi

java - Selenium Webdriver 通信错误

转载 作者:行者123 更新时间:2023-11-30 02:45:06 25 4
gpt4 key购买 nike

我正在做一个 java 项目,它使用 selenium web 驱动程序自动执行网站中的任务,但出现错误。

设置System.setProperty("webdriver.chrome.driver","chrome驱动程序的路径");

有这个方法

public boolean openBrowserAndLoadUrl(String url) {          
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions","--start-maximized");
WebDriver driver = new ChromeDriver(options);
if(driver==null)
return false;
driver.get("https://www.google.co.in");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
return true;
}

pom.xml

<org.seleniumhq-version>2.53.1</org.seleniumhq-version>

<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${org.seleniumhq-version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.23</version>
</dependency>

驱动程序”变量已初始化,并且 Google Chrome 已打开。 Eclipse 调试显示此处发生异常 driver.get("https://www.google.co.in");

两次出现两种类型的错误!两个堆栈跟踪如下所示。

org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.

Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09' System info: host: 'fms-dev', ip: '192.168.1.56', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_101'

Driver info: driver.version: RemoteWebDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=C:\Users\fms\AppData\Local\Temp\scoped_dir3000_27723}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=54.0.2840.71, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 05d03919d730cf29cb2267aba8f0de45 at

org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665) at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:316)

后来我得到了这个错误

org.openqa.selenium.WebDriverException: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"4492.1","isDefault":true},"id":1,"name":"","origin":"://"}

(Session info: chrome=54.0.2840.71) (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 39 milliseconds Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09' System info: host: 'dev-pc', ip: '192.168.1.56', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_101' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=C:\Users\dev\AppData\Local\Temp\scoped_dir960_31279}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=54.0.2840.71, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: a1f32c762f3525f55845afd4ab824af5 at

sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:316)

在进一步的研究中,我了解到很多人都有这个问题,但除了版本不兼容问题之外,我没有得到任何解决方案。但我正在使用下载的 chromedriver.exe

此外,早些时候,使用此 chrome 驱动程序和相同的 selenium 版本,所有 selenium 步骤均已成功。。不知道为什么现在变成这样了!请帮忙。

最佳答案

您的 Windows 系统中安装的 Chrome 浏览器可能已自动更新。
您可以从 Chrome 驱动程序网站下载最新的驱动程序。

关于java - Selenium Webdriver 通信错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40419979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com