How would you check if a popup window exists using selenium webdriver?

拈花ヽ惹草 提交于 2019-12-24 05:04:40

问题


I am running link tests on an application and one of the links brings up a login popup window. Is there a way to check for that? I tried treating it like an alert but it didn't work.

try
   {
     WebDriverWait wait = new WebDriverWait(driver, 2);
     wait.until(ExpectedConditions.alertIsPresent());
     Alert alert = driver.switchTo().alert();
     alert.accept();
     reportAlertPresent = true;
    }

回答1:


On driver.switchTo().alert(), a org.openqa.selenium.NoAlertPresentException can be thrown, which is an unchecked (i.e. RuntimeException).

You could catch it and possibly do this in a loop.




回答2:


If your popup is inside an iframe then,

 WebElement frameID = driver.findElement(By.(locator));
 driver.switchTo().frame(frameID);

If it is a window, you can use window handles. the below links might help

http://www.thoughtworks.com/products/docs/twist/2.3/help/how_do_i_handle_popup_in_selenium2.html

How to handle Pop-up in Selenium WebDriver using Java



来源:https://stackoverflow.com/questions/24911681/how-would-you-check-if-a-popup-window-exists-using-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!