Enabling popup windows in Chrome by Selenium

2019-01-15 20:54发布

My apologies in advance if my question sounds primary, I am very new at QA and 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?

3条回答
叛逆
2楼-- · 2019-01-15 21:05

If anyone is still encountering this problem, it's probably because they are on an old version of ChromeDriver. Popup blocking was disabled by default from version 21+

Reference: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1291

查看更多
可以哭但决不认输i
3楼-- · 2019-01-15 21:20

There is also another option to enable popup windows. Because sometimes your company may block you from accessing any application in admin mode. If the above method fails to work, you can use the below codes to enable pop ups.

WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("chrome://settings/content");
Thread.sleep(4000);
driver.switchTo().frame("settings");
Thread.sleep(2000);
driver.findElement(By.xpath("//input[@type='radio' and @name='popups']")).click();
Thread.sleep(4000);
driver.findElement(By.id("content-settings-overlay-confirm"));
Thread.sleep(4000);
  • Use the above code before starting your test.
查看更多
贼婆χ
4楼-- · 2019-01-15 21:21

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

EDIT: Just found the same solution on this site.

查看更多
登录 后发表回答