我正在使用关键字驱动的框架并从DS.java
文件调用它。
使用Selenium Webdriver在浏览器窗口之间切换
- 浏览器window01:我的如下要求执行任务,
- 打开一个新的window02浏览器通过点击window01 URL,
- 在window02,执行某些任务,
- 关闭window02和开关控制window01,
- 我收到提示
org.openqa.selenium.NoSuchWindowException: no such window. (Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
我已经完成了下面提到的代码,但它没有为我工作。
(able to get the window handle here: CDwindow-b20d349b-3cb5-42ed-9f77-5229c88d4300)
public static void store_ParentWindow(String TCID,String vTCD,String vKW) throws IOException, InterruptedException, AWTException, BiffException, ParseException{
String parentWindow = driver.getWindowHandle();
DS.envVar.put("parentWindow", parentWindow);
Thread.sleep(5000);
System.out.println(DS.envVar.get("parentWindow"));
}
public static void switch_ParentWindow(String TCID,String vTCD,String vKW) throws IOException, InterruptedException, AWTException, BiffException, ParseException{
driver.close();
String parentWindow = DS.envVar.get("parentWindow");
System.out.println(DS.envVar.get("parentWindow"));
driver.switchTo().window(parentWindow);
driver.switchTo().defaultContent();
Thread.sleep(5000);
}
谁能帮我看这个问题?
你的代码不适合我,因为我需要他们在2个不同的步骤>顺便说一句,我没有在捕获父窗口句柄或切换到新窗口并关闭它的问题。唯一的问题是,在关闭新窗口后,我无法切换回父窗口 – xxan
对于切换回到上一个窗口,使用'driver.switchTo()。window(winHandleBefore);' –
我试过了,没有运气。感谢您的答复 – xxan