简体   繁体   English

如何使用Selenium处理PopUpWindow

[英]How to handle PopUpWindow with Selenium

I've tried to handle a specific PopUp / new Window in Java with SeleniumServer but it just doesn't work. 我试图用SeleniumServer处理Java中的特定PopUp / new Window ,但是它不起作用。 I've done: 我弄完了:

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();

    }
}

But it doesn't recognize the new window. 但是它无法识别新窗口。 If I use getAllWindowIDs or names or titles, it just returns one, the primary window. 如果我使用getAllWindowIDs或名称或标题,它只会返回一个,即主窗口。

If I use selenium.waitForPopUp("foobar", "9999") it fails after the timeout, that is why I use a regular Thread.sleep() . 如果我使用selenium.waitForPopUp("foobar", "9999")则在超时后失败,这就是为什么我使用常规Thread.sleep()

What else can I do? 我还可以做些什么?

首先手动进行操作,在弹出窗口出现后单击按钮,只需使用硒ide在该弹出窗口中记录一些内容即可。如果您获得窗口ID标题,然后在“ waitforpopup”命令中使用该“ id”。

This can help: 这可以帮助:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM