
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Disable Images in Selenium ChromeDriver
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.
Syntax
prefs.put("profile.managed_default_content_settings.images", 2);
Let’s us make an attempt to disable all image 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 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); driver.get("https://www.tutorialspoint.com/index.htm/"); } }
Output
Advertisements