Java Selenium Webdriver - Chrome - 切换窗口并返回 - 无法从渲染器接收消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22382628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium Webdriver - Chrome - Switch Window and back - Unable to receive message from renderer
提问by Nihir Das
This is my first question on Stack Overflow. Thanks to all StackOverflow users who keeps technology passion ticking.
这是我关于 Stack Overflow 的第一个问题。感谢所有保持技术热情的 StackOverflow 用户。
I am testing a web application with selenium Webdriver . It is payment webpage where, after selecting Payment method as 'PayPal' it opens up a new Popup , a PayPal popup and i Switch window to Paypal , do all my necessary Transaction. And once the Transaction is successful , automatically the paypal popup is closed, and i am not able to return to my original window from where i have initiated transaction.
我正在使用 selenium Webdriver 测试 Web 应用程序。这是付款网页,在选择付款方式为“PayPal”后,它会打开一个新的弹出窗口、一个 PayPal 弹出窗口,然后我将窗口切换到 Paypal,执行所有必要的交易。一旦交易成功,paypal 弹出窗口会自动关闭,我无法从我发起交易的地方返回到我的原始窗口。
I am getting following error in eclipse console:
我在 Eclipse 控制台中收到以下错误:
Starting ChromeDriver (v2.9.248315) on port 25947
[70.164][SEVERE]: Unable to receive message from renderer
The following details might help :
以下详细信息可能会有所帮助:
- selenium Webdriver (2.28.0)
- java - JRE7
- Google Chrome Version - Version 33.0.1750.146
- Test Framework - Test NG
- 硒网络驱动程序(2.28.0)
- java - JRE7
- 谷歌浏览器版本 - 版本 33.0.1750.146
- 测试框架 - 测试 NG
Here is my code :
这是我的代码:
// To Switch to Popup/Paypal window
String currentWindowHandle=driver.getWindowHandle();
Set<String> openWindowsList=driver.getWindowHandles();
String popUpWindowHandle=null;
for(String windowHandle:openWindowsList)
{
if (!windowHandle.equals(currentWindowHandle))
popUpWindowHandle=windowHandle;
}
driver.switchTo().window(popUpWindowHandle);
// Carraying out my paypal transaction
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id='loadLogin']")).click();
Thread.sleep(8000);
WebElement login_email = driver.findElement(By.xpath("//*[@id='login_email']"));
login_email.clear();
login_email.sendKeys(Keys.BACK_SPACE);
login_email.sendKeys("[email protected]");
WebElement login_password = driver.findElement(By.xpath("//*[@id='login_password']"));
login_password.clear();
login_password.sendKeys("abcxyz");
// Next Click is Final Click on PayPal
driver.findElement(By.xpath("//*[@id='submitLogin']")).click();
// Transaction is finished on PayPal side and it automatically popup is closed
//Now i am trying to switch to my last working(original) window
driver.switchTo().window("My Web Page Title");
采纳答案by Richard
You should be using:
你应该使用:
driver.switchTo().window(currentWindowHandle);
回答by Nihir Das
The problem is resolved.
问题解决了。
The place where I was declaring currentWindowHandle was after clicking and it takes the new window as the Current Window handle.
我声明 currentWindowHandle 的地方是在单击之后,它将新窗口作为当前窗口句柄。
I just moved below statement to before the new window click event.
我只是将下面的语句移到新窗口单击事件之前。
String currentWindowHandle=driver.getWindowHandle();
Thanks all for your time and Help.
感谢大家的时间和帮助。
回答by sumit kumar pradhan
It causes because page took long time to load , you need add additional line to your chromedriver option.
这是因为页面需要很长时间才能加载,您需要在 chromedriver 选项中添加额外的行。
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);