Some testing scenarios requires that the Popup blocking be disabled. In this article we will look at ways for disabling popup blocker for different browser
Disabling Popup blocker in InternetExplorer
This can be done by setting a registry setting.
from _winreg import *
def set_popupblocker_status(enabled):
key = OpenKey(HKEY_CURRENT_USER, r"Software\Microsoft\Internet Explorer\New Windows", 0, KEY_ALL_ACCESS)
SetValueEx(key, "PopupMgr", 0, REG_SZ, enabled)
CloseKey(key)
set_popupblocker_status("no")
Disabling Popup blocker in Firefox
For firefox, this can be done using a preference setting dom.disable_open_during_load
in the Firefox profile
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("dom.disable_open_during_load", False)
driver = webdriver.Firefox(firefox_profile=profile)
Disabling Popup blocker in Chrome
For chrome we need to use the prefs option
from selenium import webdriver
option = webdriver.ChromeOptions()
chrome_prefs = {}
option.experimental_options["prefs"] = chrome_prefs
chrome_prefs["profile.default_content_settings"] = { "popups": 1 }
driver = webdriver.Chrome(chrome_options=option)
Disabling Popup blocker in PhantomJS
PhantomJS had no functionality of a popup blocker.
Disabling Popup blocker in Safari
To disable popup blocker in Safari we need to change the defaults using terminal
$ defaults write com.apple.Safari WebKitJavaScriptCanOpenWindowsAutomatically -bool true
$ defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaScriptCanOpenWindowsAutomatically -bool true
Note: These settings are global settings and will impact all Safari instances