Webinar - Join us on 26th Oct. to hear all about Selenium 4 and its exciting new features from David Burns, Core Contributor to Selenium. Register here

Enable and Disable Pop-Ups

Enable or disable pop-ups in your Selenium tests across different browsers

Enable pop-ups

You can enable pop-ups in Chrome, IE and Safari as follows:

Pop-ups are enabled by default (as the pop-up blocker is disabled, by default).

To enable the popups in IE, use the browserstack.ie.enablePopups capability.

caps.setCapability("browserstack.ie.enablePopups", "true");
caps["browserstack.ie.enablePopups"] = "true"
desiredCap.SetCapability("browserstack.ie.enablePopups", "true");
caps["browserstack.ie.enablePopups"] = "true"
var capabilities = {
  "browserstack.ie.enablePopups" : "true"
}
$caps["browserstack.ie.enablePopups"] = "true";
$caps->{"browserstack.ie.enablePopups"} = "true";

To enable the popups in Safari, use the browserstack.safari.enablePopups capability.

caps.setCapability("browserstack.safari.enablePopups", "true");
caps["browserstack.safari.enablePopups"] = "true"
desiredCap.SetCapability("browserstack.safari.enablePopups", "true");
caps["browserstack.safari.enablePopups"] = "true"
var capabilities = {
  "browserstack.safari.enablePopups" : "true"
}
$caps["browserstack.safari.enablePopups"] = "true";
$caps->{"browserstack.safari.enablePopups"} = "true";

Disable pop-ups

Note:
  • For all browsers except Chrome, the pop-ups are disabled by default.
  • If you have enabled them using the steps in the previous section, remove the code that disables the pop-up blocker to disable popups

Disable pop-ups in Chrome

For Chrome, pop-ups are enabled by default i.e. the pop-up blocker is disabled by default. To enable the pop-up blocker i.e. to block pop-ups, pass disable-popup-blocking argument under the excludeSwitches of a chromeOptions capability, as shown below:

ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches",Arrays.asList("disable-popup-blocking"));
caps.setCapability(ChromeOptions.CAPABILITY, options);
caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps["chromeOptions"] = {}
caps["chromeOptions"]["excludeSwitches"] = ["disable-popup-blocking"]
using OpenQA.Selenium.Chrome;

ChromeOptions options = new ChromeOptions();
options.AddExcludedArgument("disable-popup-blocking");
desired_cap = {
 'browser': 'chrome',
 'browser_version': 'latest',
 'os': 'Windows',
 'os_version': '10',
 'build': 'Python Sample Build',
 'name': 'Pop-ups testing'
}
desired_cap["chromeOptions"] = {}
desired_cap["chromeOptions"]["excludeSwitches"] = ["disable-popup-blocking"]

driver = webdriver.Remote(
    command_executor='https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub',
    desired_capabilities=desired_cap
    )
# Rest of the code goes here
var capabilities = {
  "browserName" : "chrome",
  "chromeOptions" : {
    "excludeSwitches" : ["disable-popup-blocking"]
  }
}
$chromeoptions = array("excludeSwitches"=>array("disable-popup-blocking"));
$caps = array("platform"=>"WINDOWS", "browserName"=>"chrome", "chromeOptions"=>$chromeoptions);
$caps->{"chromeOptions"} = { "excludeSwitches" => ("disable-popup-blocking") };

We're sorry to hear that. Please share your feedback so we can do better







Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better







Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert