你好我正在使用的是弹出窗口 所以当我点击一个按钮,即“click1”时,它会弹出一个div窗口.. 所以在这个弹出窗口中,我可以使用动作类
来玩元素WebElement element = wd.findElement(By.className("qx-window"));
Actions actions = new Actions(wd);
actions.moveToElement(element).click().perform();
现在从这个弹出窗口,当我点击另一个按钮时,它再次弹出另一个弹出窗口,我再次尝试使用动作类,但无法将注意力设置在新弹出窗口
所以场景是主窗口 - > popup-> popup
我能否从首次弹出中删除焦点
听到下面的selenium代码不起作用,这就是我使用动作的原因
for (String popup : wd.getWindowHandles())
{
wd.switchTo().window(popup);
}
答案 0 :(得分:0)
尝试以下流程
//Store main window handle in one variable
String mainWindowHandle = driver.getWindowHandle();
//click something on window to open popup1
Set<String> windowHandles = driver.getWindowHandles(); //It returns Set of available window handles
//from above set get popup1 handle and switch control to popup1
//==switch control to pop-up1
windowHandles.remove(mainWindowHandle);
String popup1Handle=(String)windowHandles.toArray()[0];
driver.switchTo().window(popup1Handle);
//do your operations in popup1
//===== YOUR ACTIONS GOES HERE FOR POPUP1
//click on button in popup1 which will open popup2
//switch the control to popup2
windowHandles = driver.getWindowHandles(); //It returns Set of available window handles, here it returns 3 window handles
windowHandles.remove(mainWindowHandle);
windowHandles.remove(popup1Handle);
String popup2Handle=(String)windowHandles.toArray()[0];
driver.switchTo().window(popup2Handle);
//do your operations in popup2
//===== YOUR ACTIONS GOES HERE FOR POPUP2
driver.close(); // this will close popup2 as control is in popup2
//switch the control to main window again
driver.switchTo().window(mainWindowHandle);