Disable images in Selenium Google ChromeDriver.

SeleniumAutomation TestingTesting Tools

We can disable images in Selenium in chromedriver. The images are sometimes disabled so that page load takes less time and execution is quick. In Chrome, we can do this with the help of the prefs setting.


prefs.put("profile.managed_default_content_settings.images", 2);

Let’s us make an attempt to disable all image from the below page −


Code Implementation.

import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.HashMap;
import java.util.Map;
public class ChromeDisableImg {
   public static void main(String[] args) throws IOException {
      System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
      Map<String, Object> prefs = new HashMap<String, Object>();
      // browser setting to disable image
      prefs.put("profile.managed_default_content_settings.images", 2);
      //adding capabilities to browser
      ChromeOptions op = new ChromeOptions();
      op.setExperimentalOption("prefs", prefs);
      // putting desired capabilities to browser
      WebDriver driver= new ChromeDriver(op);


Updated on 28-Dec-2020 13:17:30