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

查看:1336
本文介绍了通过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 。因此,使用 ChromeOptions DesiredCapabilities ,使用 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);

编辑:刚刚找到相同的解决方案网站

Just found the same solution on this site.

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

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