您将如何使用Selenium Webdriver检查是否存在弹出窗口? [英] How would you check if a popup window exists using selenium webdriver?

查看:2772
本文介绍了您将如何使用Selenium Webdriver检查是否存在弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在应用程序上运行链接测试,其中一个链接会弹出一个登录弹出窗口.有没有办法检查?我尝试将其视为警报,但没有用.

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;
    }

推荐答案

如果弹出窗口位于iframe中,则

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

如何处理Selenium WebDriver中的弹出窗口使用Java

这篇关于您将如何使用Selenium Webdriver检查是否存在弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆