通过 Selenium 在 Chrome 中启用弹出窗口 [英] Enabling popup windows in Chrome by Selenium

查看:60
本文介绍了通过 Selenium 在 Chrome 中启用弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的问题听起来很重要,我提前道歉,我是 QA 和 Selenium 的新手.

My apologies in advance if my question sounds primary, I am very new at QA and Selenium.

我正在使用 Java 和 Selenium 编写测试,在我的测试步骤之一,当我单击一个按钮时,它应该打开另一个窗口,但 Chrome 阻止了弹出窗口,我可以通过 Selenium 启用弹出窗口吗?

I am using Java and Selenium to write a test, at one of my test's step when I click on a button it is supposed to open another window but Chrome blocks the popup window, can I enable popup by Selenium?

推荐答案

好吧,您需要使用自定义配置来初始化 ChromeDriver,这将禁用该标志来阻止弹出窗口.从这个 站点,它的命令行开关是 disable-popup-blocking.因此,使用 ChromeOptionsDesiredCapabilities,您可以使用 DesiredCapabilities.setCapability() 函数.

Well, you need to initialize the ChromeDriver with a customized configuration which will disable the flag to block popups. From this site, the command line switch for it is disable-popup-blocking. So, using ChromeOptions and DesiredCapabilities, you add the desired config using the DesiredCapabilities.setCapability() function.

ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("disable-popup-blocking");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);

刚刚在这个 上找到了相同的解决方案网站.

这篇关于通过 Selenium 在 Chrome 中启用弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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