Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
How to check if an image is displayed on page using Selenium?
Next article icon

How to disable images in chrome using Selenium java?

Last Updated : 17 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Disabling images in Chrome during automated testing can enhance performance and speed up your Selenium tests. This is particularly useful when dealing with large web pages or when you want to focus on specific elements without the distraction of images.

In this guide, we'll walk you through how to disable images in Chrome using Selenium Java, ensuring that your test automation runs efficiently.

Prerequisites

  • Java Development Kit (JDK) must be installed on your system.
  • Eclipse IDE or any Java-compatible IDE.
  • Basic knowledge of Java and Selenium WebDriver.
  • Selenium WebDriver and Browser Driver installed.

Example

Java
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions;  public class DisableImagesInChrome {     public static void main(String[] args) {         // Set up ChromeOptions to disable images         ChromeOptions options = new ChromeOptions();         options.addArguments("start-maximized");  // Maximize the browser window          // Disable images using Chrome preferences         options.addArguments("profile.managed_default_content_settings.images=2"); // 2 disables images          // Set the path for the ChromeDriver executable         System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); // Update the path to your ChromeDriver          // Initialize WebDriver with ChromeOptions         WebDriver driver = new ChromeDriver(options);          try {             // Navigate to the desired website             driver.get("https://geeksforgeeks.org");  // Example URL              // Optional: Pause to observe the result             Thread.sleep(5000);  // Pause for 5 seconds to see the result          } catch (InterruptedException e) {             // Handle interruption             e.printStackTrace();         } finally {             // Close the browser             driver.quit();  // Ensure the browser is closed         }     } } 

Output

Screenshot-2024-09-11-200317
GeeksforGeeks website after disabling images

Conclusion

Disabling images in Chrome using Selenium Java is a straightforward process that can significantly improve the speed of your test executions. By configuring ChromeOptions to disable images, you streamline the web page loading process, making your tests more efficient.

With the steps outlined above, you can easily implement this optimization in your Selenium tests, leading to faster and more focused automation.



Next Article
How to check if an image is displayed on page using Selenium?

R

rd9437
Improve
Article Tags :
  • Software Testing
  • Selenium

Similar Reads

  • How to click on an image using Selenium in Java?
    Selenium, a popular tool for automating web application testing across browsers, often requires image interaction. In this article we will discuss how to clicking on image using Selenium in Java. PrerequisitesJava Development Kit (JDK) installed.Selenium WebDriver library added to your project.A sup
    3 min read
  • How to check if an image is displayed on page using Selenium?
    When it comes to web automation and testing, It is important to confirm that a picture has been rendered on a particular page. This is because bad content loading is regarded as a big issue in the good user interface. Users can easily get frustrated with missing or broken images, hence the need for
    3 min read
  • How to download Google Image Using java Selenium?
    Downloading images from Google using Java Selenium is a task that can come in handy for various automation projects. Whether you're building a dataset for machine learning, collecting images for research, or simply want to automate the process of downloading images, Selenium provides a robust soluti
    5 min read
  • How to Handle Alert in Selenium using Java?
    Imagine filling out a form online and accidentally missing some information. You only know if you made a mistake if the website tells you somehow, like with a pop-up message. This article explains what those pop-up messages are called in Selenium (alerts) and how to deal with them in your automated
    6 min read
  • How to download File in Selenium Using java
    Automating the file download process is essential in web automation testing, especially for validating functionalities involving document downloads such as PDFs, images, or CSV files. However, Selenium WebDriver doesn’t directly handle file downloads. To overcome this limitation, we can configure th
    2 min read
  • How to Handle iframe in Selenium with Java?
    In this article, we are going to discuss how to handle the iframe in Selenium with Java. The following 6 points will be discussed. Table of Content What are iframes in Selenium?Difference between frame and iframe in SeleniumSteps to Identify a Frame on a Page?How to Switch Over the Elements in ifram
    11 min read
  • How do I pass options to the Selenium Chrome driver using java?
    Selenium WebDriver is a widely used tool for automating web browsers. When working with Selenium ChromeDriver, passing custom options to the browser allows you to tailor the browsing experience based on your test requirements. Whether you're running tests in headless mode, disabling notifications, o
    2 min read
  • How to Open a Browser in Headless Mode in Selenium using Java?
    Headless testing has become a significant trend in modern web automation, offering numerous advantages for developers and testers. In Selenium, running tests in headless mode allows browsers to operate without the graphical user interface (GUI). This article delves into the concept of headless brows
    6 min read
  • How to Run Gecko Driver in Selenium Using Java?
    Selenium is a well-known software used for software testing purposes. It consists of three parts: Selenium IDE, Selenium WebDriver, and Selenium Grid. Selenium WebDriver is the most important. Using WebDriver, online website testing can be done. There are three main WebDriver implementations: Chrome
    5 min read
  • How to Run Internet Explorer Driver in Selenium Using Java?
    Selenium is a well-known software used for software testing purposes. Selenium consists of three parts. One is Selenium IDE, one is Selenium Webdriver & the last one is Selenium Grid. Among these Selenium Webdriver is the most important one. Using Webdriver online website testing can be done. Th
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences