How to Disable images in Selenium Google ChromeDriver?

SeleniumAutomation TestingTesting Tools

We can disable images in Selenium Google chromedriver. The images are disabled so that page load is quicker and execution time is also less. In chromedriver, we have to configure the below browser parameter −

profile.managed_default_content_settings.images, and set its value to 2.

Syntax

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

Let’s try to disable images from the below page −

Example

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 ImageDisable {
   public static void main(String[] args) throws IOException {
      System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      Map<String, Object> p = new HashMap<String, Object>();
      // browser setting to disable image
      p.put("profile.managed_default_content_settings.images", 2);
      //capabilities added to browser
      ChromeOptions opt = new ChromeOptions();
      opt.setExperimentalOption("prefs", p);
      // associating desired capabilities to browser
      WebDriver driver = new ChromeDriver(opt);
      driver.get("https://www.tutorialspoint.com/about/about_careers.htm");
   }
}

Output

raja
Published on 28-Dec-2020 11:10:09
Advertisements