2

I am using the java and selenium to write the test script for automation. On here the target automated Org has some reminder pop-up windows so it makes the confusion of taking in the command of driver.getWindowHandles() command on my results.

I try the below code to try to Block the pop-up windows on the chrome

    System.setProperty("webdriver.chrome.driver", "//chrome path in system//");
    ChromeOptions options  = new ChromeOptions();
    options.setExperimentalOption("excludeSwitches", "disable-popup-blocking");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new ChromeDriver(capabilities);

But it's not working it's given the below error and prevent the chrome to launch:

from unknown error: cannot parse excludeSwitches
from unknown error: must be a list

So what I should do for close those pop-up windows. Any answer is appreciated. I am using the chrome version: '2.29.461591' and java.version: '1.8.0_92'

vinS
  • 1,417
  • 5
  • 24
  • 37
Mohanraj Sivalingam
  • 231
  • 1
  • 8
  • 21
  • 1
    Have a look at this workaround... https://stackoverflow.com/questions/7742852/popup-blocking-in-google-chrome-causing-issues-with-capybara-rspec-tests. I think you should look at the answer by "Md. Nazmul Haque Sarker" as it seems more relevant to current chrome verion. – Grasshopper Dec 07 '17 at 10:35
  • Thanks for the reply.I am a new bee for a test automation. I am not understanding clearly on that link. on your suggested answer. css_selector_for_iframe = 'iframe[name="settings"]' driver.get('chrome://settings/content') iframe = driver.find_element_by_css_selector(css_selector_for_iframe) driver.switch_to_frame(iframe) driver.find_element_by_name('popups').click() click_element(driver, '#content-settings-overlay-confirm') driver.switch_to_default_content() – Mohanraj Sivalingam Dec 07 '17 at 11:25

2 Answers2

2

Try sending the "disable-popup-blocking" argument by type-casting it as a list. This works for me in python:

chrome_options.add_experimental_option("excludeSwitches", ["disable-popup-blocking"])
fcdt
  • 2,371
  • 5
  • 14
  • 26
0

You can try below code it is working fine for me:

    System.setProperty("webdriver.chrome.driver", "//chrome path in system//");
    ChromeOptions options  = new ChromeOptions();
    //options.addArguments("incognito");
    options.addArguments("--disable-popup-blocking");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new ChromeDriver(capabilities);
Abhishek Yadav
  • 459
  • 5
  • 16
  • Sorry dude. It launches the chrome in the as an incognito window but it's failed to block the pop-up Browser window on running my automation test script :( – Mohanraj Sivalingam Dec 07 '17 at 11:33
  • Updated the code for you, may be -- needs to added to set the chrome option on your env. – Abhishek Yadav Dec 07 '17 at 11:39
  • "needs to add to set the chrome option on your env." means I have done for the block the pop-up windows for manually..? Because it's also failed to block the pop-up Browser windows for chrome in my test :( – Mohanraj Sivalingam Dec 07 '17 at 11:50
  • unfortunately for selenium 4 i tried this but not working guys! – gumuruh May 20 '22 at 00:39