Enabling popup windows in Chrome by Selenium
Solution 1
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.
Solution 2
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.
Solution 3
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
LoveLovelyJava
Updated on June 07, 2022Comments
-
LoveLovelyJava almost 2 years
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?
-
Bhuvanesh Mani about 6 yearsYes, options.addArguments("disable-popup-blocking"); doesn't work for me. Do we have any other alternate options to "Allow" the popups? I am somehow not comfortable to write code to go to chrome://settings/content page to make the popups to "Allowed" It looks vague to me
-
Bhuvanesh Mani about 6 yearsI just tried this code in my personal laptop (not work) and found this doesnt control "Popups" anymore. Its always "Blocked" irrespective of line > options.addArguments("disable-popup-blocking"); I am using Chrome V65.0
-
JRodDynamite about 6 years@BhuvaneshMani - Can you manually check from the settings if the config has been set once you initialized the ChromeDriver?
-
Admin over 5 yearsI have
In order to provide you with better service, we use cookies on our pages. By using this site, you agree to our Cookies Policy.
slidding popup while launching my site but unable to disabled that while launching using chromedriver.