简体   繁体   English

如何使用Selenium WebDriver处理叠加/弹出窗口

[英]How to handle overlay/popup window using selenium webdriver

I am trying to automate initial configuration(of my server) through webpage. 我正在尝试通过网页自动(服务器的)初始配置。 After hitting my server ip https:/localhost:4443 and entering my credentials ,i get a window to change password(overlay/popup window). 击中我的服务器ip https:/ localhost:4443并输入我的凭据后,我得到一个更改密码的窗口(覆盖/弹出窗口)。

Problem:- if i browse the same ip from another m/c or from another browser , i get a window over window ie one more window over change password window( Please click the link to see the screenshot ). 问题:-如果我从另一台m / c或另一台浏览器浏览相同的ip,则会在窗口上方显示一个窗口,即在更改密码窗口上显示一个窗口( 请单击链接以查看屏幕截图 )。

What i tried is to get the handle of the window but its not working, its providing one handle only. 我尝试的是获取窗口的句柄,但它不起作用,仅提供一个句柄。

**Its not frame also. **它也没有框架。

HTML code -- https://dl.dropboxusercontent.com/u/91420517/Html_Code.JPG HTML代码-https://dl.dropboxusercontent.com/u/91420517/Html_Code.JPG

Here's my code 这是我的代码

    WebDriver driver=new FirefoxDriver();
    driver.get("https://localhost:4443/ControlPoint/");
    driver.findElement(By.xpath("//*[@id='name']")).sendKeys("xxxxxx");
    driver.findElement(By.xpath("//*[@id='pass']")).sendKeys("xxxxxx");
    driver.findElement(By.xpath("//*[@id='loginForm123']/div[6]/div[1]/div")).click();

    Set<String> winIds = driver.getWindowHandles();
    System.out.println("Total Windows --- " + winIds.size());    // its resulting the size as 1 which is not correct.
    Iterator<String> it = winIds.iterator(); 
    String mainWin=it.next();
    String changeWin=it.next();
    String shareWin =it.next();
    driver.switchTo().window(shareWin);
    String warning = driver.findElement(By.xpath("html/body/div[4234]/div[1]/span")).getText();  // to get the text on 3 window
    System.out.println(warning);

How to resolve this issue .Please help. 如何解决此问题。请提供帮助。 Any other way to click on buttons on window 3. 单击窗口3上按钮的任何其他方式。

If the additional window is opened asynchronously, then possibly you are checking for it (with getWindowHandles() ) too early, before it has been created - this is a common issue with Selenium tests and asynchronous page updates. 如果附加窗口是异步打开的,则可能在创建之前就过早检查了它(使用getWindowHandles() )-这是Selenium测试和异步页面更新的常见问题。

If this is the issue, it can be solved by trying a few times with a wait in between, checking each time whether a new window has appeared. 如果这是问题所在,则可以通过在两次等待之间进行几次尝试来解决,每次检查是否都出现了新窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Selenium WebDriver处理“使用Google登录”弹出窗口 - How to handle 'Log in with Google' popup window using Selenium WebDriver 如何使用 Selenium/Java 处理 WebDriver 中不存在的弹出窗口 window? - How to handle a popup window that does not exist in the WebDriver with Selenium/Java? 如何在Selenium Webdriver中安全处理弹出窗口 - How can I handle popup window safely in selenium webdriver 如何使用Java通过Selenium WebDriver处理fancybox弹出窗口 - How to handle fancybox popup through Selenium WebDriver using Java 如何使用Selenium WebDriver处理Excel下载弹出窗口 - How to handle Excel download popup using Selenium WebDriver 如何使用 Selenium Webdriver 处理浏览器身份验证弹出窗口 - How to Handle Browser Authentication popup using Selenium Webdriver 如何使用python处理Selenium WebDriver的身份验证弹出窗口? - How to handle authentication popup with Selenium WebDriver using python? 如何使用带有Java的Selenium WebDriver处理日历弹出窗口? - How to handle calendar popup using Selenium WebDriver with Java? 如何使用 Java 处理 Selenium WebDriver 的身份验证弹出窗口 - How to handle authentication popup with Selenium WebDriver using Java 如何使用 Java 使用 Selenium WebDriver 在 Chrome 中处理身份验证弹出窗口 - How to handle authentication popup in Chrome with Selenium WebDriver using Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM