我正在使用關鍵字驅動的框架並從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