我对硒 3.13.0 和 chrome 版本 79.0.3945.130 和 java 有问题。我编写此代码用于测试必须在 2 个窗口之间切换的网页。当我开始运行此脚本时,一切正常,但是当驱动程序切换到新窗口时,它似乎不再可用!很长一段时间后,我得到了这个错误。 有谁知道问题出在哪里?
(我确信程序的控制会退出循环并切换到新窗口,但似乎驱动程序在离开循环后会丢失。
一些函数如driver.quit((或driver.getWindowHandles((在退出循环后工作,但其他一些函数如driver.getPageSource((或driver.manage((.window((.maximize((不起作用并导致此错误。
这是我的示例代码:
public class myClassFirst {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","Driver_Path");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize(); //it works correctly
driver.get("Web_page_Url");
Thread.sleep(15000); //to load page
System.out.println("finish waiting ...");
/*
some script here
*/
// go to appropriate frame
driver.switchTo().defaultContent();
driver.switchTo().frame("Faci3");
driver.switchTo().frame(driver.findElement(By.name("Commander")));
Set<String> s = driver.getWindowHandles();
System.out.println(s); //print windowID of current window(1)
//select button element
WebElement prepareToPrint = driver.findElement(By.id("PreparePrint"));
prepareToPrint.click();
Thread.sleep(5000); //to load new window(2)
String sThis = driver.getWindowHandle(); //get windowID of current window(1)
for (String winId:driver.getWindowHandles()) {
if (!winId.equals(sThis)) {
driver.switchTo().window(winId); //switch to new window(2)
System.out.println(winId); //print windowID of new window(2)
break;
}
}
System.out.println("exit from the loop");
driver.manage().window().maximize(); //From here does not work anymore(real line 92)
Actions builder = new Actions(driver);
builder.contextClick().perform();
System.out.println("End = Finish");
driver.quit();
}
}
这是输出:
finish waiting ...
[CDwindow-9B003436EA7F9E41C56694893D686231]
CDwindow-7205BC1AD0022BD28BFD18FCD4FA379B
exit from the loop
[1579772104.277][SEVERE]: Timed out receiving message from renderer: 300.000
[1579772104.280][SEVERE]: Timed out receiving message from renderer: -0.003
Exception in thread "main" org.openqa.selenium.TimeoutException: timeout
(Session info: chrome=79.0.3945.130)
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:14.902Z'
System info: host: 'DESKTOP-BT6SU1U', ip: '192.168.67.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.130, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: C:UsersSadellAppDataLoc...}, goog:chromeOptions: {debuggerAddress: localhost:61628}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 5b36cc7b69534ede85d7c957306c2626
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:614)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:638)
at org.openqa.selenium.interactions.Actions.perform(Actions.java:594)
at myClassFirst.main(myClassFirst.java:92)
Process finished with exit code 1
Selenium WebDriver 默认等到页面完全加载。但是,您可以告诉它不要使用,或者使用另一个PageLoadStrategy。
以下内容应该对您有所帮助。
ChromeOptions options = new ChromeOptions();
options.setPageLoadStrategy(PageLoadStrategy.NONE);
当我在使用 EdgeDriver 遇到同样的问题时,这篇文章帮助了我。 https://www.skptricks.com/2018/08/timed-out-receiving-message-from-renderer-selenium.html
试试这个 driver.switchTo
((.window(window(.manage((.window((.maximize((此错误消息...
[1579772104.277][SEVERE]: Timed out receiving message from renderer: 300.000
[1579772104.280][SEVERE]: Timed out receiving message from renderer: -0.003
Exception in thread "main" org.openqa.selenium.TimeoutException: timeout
(Session info: chrome=79.0.3945.130)
Build info: version: '3.13.0', revision: '2f0d292', time: '2018-06-25T15:32:14.902Z'
.
.
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.130, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: C:UsersSadellAppDataLoc...}, goog:chromeOptions: {debuggerAddress: localhost:61628}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
。表示ChromeDriver无法切换到新的TAB。
您的主要问题是您使用的二进制文件版本之间的不兼容,如下所示:
您正在使用 chromedriver=79.0.3945.36- 和chrome=79.0.3945.130并且兼容
- 但是您的Selenium客户端版本是3.13.0的2018-06-25T15:32:14.902Z,几乎早了2年。
所以Selenium客户端v3.13.0,ChromeDriverv79.0和Chrome浏览器v79.0之间存在明显的不匹配
溶液
确保:
- JDK已升级到当前级别 JDK 8u222。
- 硒已升级到当前级别 版本 3.141.59。
- ChromeDriver已更新到当前的 ChromeDriver v79.0.3945.36 级别。 Chrome
- 已更新到当前的Chrome 版本 79.0级别。(根据 ChromeDriver v79.0 发行说明(
- 通过IDE清理项目工作中心,并仅使用所需的依赖项重新生成项目。
Dears
在这个问题中,我将我的网络驱动程序从chrome更改为Firefox,并暂时解决了。 我希望这也对您有所帮助。