[英]switch between two windows in browser using Selenium java
I'm trying to switch between windows and put an accountant to find out if the Selenium found the second window , but does not find it , note that he sees only 01 window , which is the Father window. 我试图在各个窗口之间切换,并请一位会计师找出Selenium是否找到了第二个窗口,但是没有找到它,请注意,他仅看到01窗口,这是父亲窗口。
how do I find It the second window and switch to It? 如何在第二个窗口中找到它并切换到它?
I use: selenium-server-standalone-2.48.2 + Eclipse + Java 1.8 我使用:selenium-server-standalone-2.48.2 + Eclipse + Java 1.8
I tried this: 我尝试了这个:
//Get all window handles
Set<String> allHandles = driver.getWindowHandles();
//count the handles Here count is=2
System.out.println("Count of windows:"+allHandles.size());
//Get current handle or default handle
String currentWindowHandle = allHandles.iterator().next();
System.out.println("currentWindow Handle"+currentWindowHandle);
//Remove first/default Handle
allHandles.remove(allHandles.iterator().next());
//get the last Window Handle
String lastHandle = allHandles.iterator().next();
System.out.println("last window handle"+lastHandle);
//switch to second/last window, because we know there are only two windows 1-parent window 2-other window(ad window)
driver.switchTo().window(lastHandle);
System.out.println(driver.getTitle());
driver.findElement(By.tagName("body")).click();
message on the console: 控制台上的消息:
我遇到了IE 11的类似问题。通过检查IE设置中所有区域的启用保护模式设置来解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.