[英]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.