[英]How to handle PopUpWindow with Selenium
我试图用SeleniumServer
处理Java中的特定PopUp / new Window
,但是它不起作用。 我弄完了:
selenium.click("css=a[title=\"Some irrelevant title\"] > div.text");
Thread.sleep(5000);
for (String s : selenium.getAllWindowNames()) {
if (s.contains("_blank")) {
selenium.selectWindow("name=" + s);
selenium.windowMaximize();
}
}
但是它无法识别新窗口。 如果我使用getAllWindowIDs
或名称或标题,它只会返回一个,即主窗口。
如果我使用selenium.waitForPopUp("foobar", "9999")
则在超时后失败,这就是为什么我使用常规Thread.sleep()
。
我还可以做些什么?
首先手动进行操作,在弹出窗口出现后单击按钮,只需使用硒ide在该弹出窗口中记录一些内容即可。如果您获得窗口ID标题,然后在“ waitforpopup”命令中使用该“ id”。
这可以帮助:
selenium.RunScript("selenium.browserbot.findElement('css=a[title='Some irrelevant title']').target='my_window'");
selenium.RunScript("window.open('', 'my_window')");
selenium.click("css=a[title='Some irrelevant title']");
selenium.selectWindow("my_window");
selenium.waitForElementPresent("element_locator_at_popup")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.