如果我的问题听起来很重要,我提前道歉,我是 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);
刚刚在这个 上找到了相同的解决方案网站.
这篇关于通过 Selenium 在 Chrome 中启用弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!