简体   繁体   English

通过Selenium Webdriver(3.x)处理自定义弹出窗口(不是默认窗口)

[英]Handling custom pop-ups (not the default windows one) through selenium webdriver (3.x)

I want to automate a scenario. 我想自动化一个方案。

When the browser lands on the website, there is a warning pop-up that requires a response to the prompt: Do you want to proceed? 当浏览器登陆网站时,将弹出警告对话框,要求对提示进行响应: 是否要继续?

There are two options Leave and Continue . 有两个选项LeaveContinue

I am trying to switch the control with the following functions but its not working. 我正在尝试使用以下功能切换控件,但无法正常工作。

    Alert alert=driver.switchTo().alert();
    driver.switchTo().alert();
    alert.accept();

If its JavaScript alert, then driver.switchTo().alert().accept(); 如果其JavaScript警报,则driver.switchTo().alert().accept(); should work by accepting the default. 应该通过接受默认值来工作。 Is this pop-up or modal window? 这是弹出窗口还是模式窗口? Did you try to switch to window and click on the button? 您是否尝试过切换到窗口并单击按钮? Also, which browser are you using? 另外,您使用的是哪种浏览器? JavaScript alert might needs to handled differently based on the browser. JavaScript警报可能需要根据浏览器进行不同的处理。 If its modal or window, then getWindowHandle() should work fine. 如果是模式窗口,则getWindowHandle()应该可以正常工作。

String newWindow = driver.getWindowHandle();
driver.switchTo().window(newWindow);
//Switching to new window
driver.findElement(By.id("buttonId"));
//Switching back to default/main window
driver.switchTo().defaultContent();

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

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