英文:
How to switch back to Parent window using selenium in Java8
问题
我使用了以下代码来操作子窗口,
driver.getWindowHandles().forEach(winHandle -> driver.switchTo().window(winHandle));
如何切换回父窗口?
英文:
I used following code for child window,
driver.getWindowHandles().forEach(winHandle -> driver.switchTo().window(winHandle));
How to switch to parent window??
答案1
得分: 2
Set<String> ids = driver.getWindowHandles();
Iterator<String> i = ids.iterator();
String parentID = i.next(); // 父窗口
while (i.hasNext()) {
String childID = i.next(); // 子窗口
driver.switchTo().window(childID); // 切换到子窗口
}
driver.switchTo().window(parentID); // 切换回父窗口
英文:
Set<String> ids = driver.getWindowHandles();
Iterator<String> i = ids.iterator();
String parentID = i.next(); //Parent Window
while(i.hasNext())
{
String childID = i.next(); //Child Windows
driver.switchTo().window(childID); // Iterating over child windows
}
driver.switchTo().window(parentID); //switching back to Parent window
答案2
得分: 1
int i = 0; // 第一个窗口 / 标签
ArrayList
driver.switchTo().window(tabs.get(i));
英文:
int i = 0; // 0 for first window / tab
ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(i));
专注分享java语言的经验与见解,让所有开发者获益!
评论