LoveLovelyJava
LoveLovelyJava

Reputation: 735

Enabling popup windows in Chrome by Selenium

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?

Upvotes: 3

Views: 24430

Answers (4)

Janek
Janek

Reputation: 25

For me worked this solution:

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-web-security");
ChromeDriver driver = new ChromeDriver(options);

Upvotes: 0

WoodenKitty
WoodenKitty

Reputation: 6529

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

Upvotes: 1

Eby
Eby

Reputation: 396

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.

Upvotes: 3

JRodDynamite
JRodDynamite

Reputation: 12613

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.

Upvotes: 7

Related Questions