Disabling Images in Internet Explorer
Internet Explorer doesn’t provide an option for disabling images through command line, so we would need to use Registry for the same
from _winreg import *
key = OpenKey(HKEY_CURRENT_USER, r"Software\Microsoft\Internet Explorer\Main", 0, KEY_ALL_ACCESS)
SetValueEx(key, "Display Inline Images", 0, REG_SZ, "no")
CloseKey(key)
We just launch the browser and test it, once the images are disabled in registry, we just launch the browser and test it
from selenium import webdriver
driver = webdriver.Ie()
driver.get("https://intellipaat.com/")
Disabling Images in Firefox
We need to change the profile settings, for disabling images in Firefox. Which can be done by using the code below
from selenium import webdriver
profile = webdriver.FirefoxProfile()
# 1 - Allow all images
# 2 - Block all images
# 3 - Block 3rd party images
profile.set_preference("permissions.default.image", 2)
driver = webdriver.Firefox(firefox_profile=profile)
Disabling Images in Chrome
Long ago chrome used to support a command line flag --disable-images, which was deprecated. Now we need to use the chrome.prefs of the chromedriver. For more details refer this
from selenium import webdriver
option = webdriver.ChromeOptions()
chrome_prefs = {}
option.experimental_options["prefs"] = chrome_prefs
chrome_prefs["profile.default_content_settings"] = {"images": 2}
chrome_prefs["profile.managed_default_content_settings"] = {"images": 2}
driver = webdriver.Chrome(chrome_options=option)
driver.get("https://intellipaat.com/")
Disabling Images in PhantomJS
PhantomJS is a headless webkit browser. It can run without an X display on a server and very useful when we want to test a website in fast mode. Disabling images on the same will make the testing more favourable.
from selenium import webdriver
driver = webdriver.PhantomJS(service_args=["--load-images=no"])
driver.get("https://intellipaat.com/")
driver.save_screenshot("intellipaat.png")
Hope this helps!
If you wish to Learn Selenium visit this Selenium Webdriver Tutorial.