通过Selenium WebDriver(3.x)处理自定义弹出窗口(不是默认窗口) [英] Handling custom pop-ups (not the default windows one) through selenium webdriver (3.x)

查看:385
本文介绍了通过Selenium WebDriver(3.x)处理自定义弹出窗口(不是默认窗口)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动化一个方案.

当浏览器登陆网站时,将弹出警告对话框,要求对提示进行响应:您要继续吗?

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?

有两个选项离开继续.

我正在尝试使用以下功能切换控件,但是它不起作用.

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();

推荐答案

如果它的JavaScript警报,则driver.switchTo().alert().accept();应该可以通过接受默认值来工作. 这是弹出窗口还是模式窗口? 您是否尝试过切换到窗口并单击按钮? 另外,您使用的是哪种浏览器? JavaScript警报可能需要根据浏览器进行不同的处理. 如果它是模式窗口,则getWindowHandle()应该可以正常工作.

If its JavaScript alert, then 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. If its modal or window, then getWindowHandle() should work fine.

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();

这篇关于通过Selenium WebDriver(3.x)处理自定义弹出窗口(不是默认窗口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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