Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothrwins@gmail.com
Vinoth Tech Solutions
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • E-Commerce Demo Application
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I
  • Home
  • Selenium Java Online Training
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Cypress Course Curriculum
    • Playwright Course Curriculum
  • Tutorials
  • Demo Sites
    • E-Commerce Demo Application
    • Practice Automation
      • Demo Page Healthcare
      • Registration Form
      • Transaction Details
      • DropDown
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
  • FAQS
  • About Me & Feedback
    • Placed Students Feedback
    • Online Training Feedback
    • LinkedIn Profile
    • TechTalk
  • Free YouTube Courses
    • Python for Automation
    • Free QA Video Courses
      • Manual Testing
      • Java For Automation
      • Selenium Webdriver
      • TestNG
      • Cucumber BDD
      • UFT(QTP) Automation
    • Free Data Science Courses
      • Artificial Intelligence for Beginners
      • Python For A.I
      • Python Pandas
      • Python NumPy
      • Mathematics for A.I

Selenium Automation Testing

  • Introduction to Automation Testing
  • Introduction to Selenium
  • Advantages and Disadvantages of Selenium WebDriver
  • Locators in Selenium
  • How to launch the browsers ? 
  • Browser Navigation Commands in Selenium
  • Handling the textbox and button using selenium
  • Handling the radio button and checkbox using selenium
  • Handling the drop downs and multi-select dropdown
  • Validate the text validation and attributes values. 
  • Handling Images
  • Handling Mouse Events
  • Handling Keyboard Events
  • Handling Alert Popup
  • Handling iFrames
  • Handling Multiple Browsers or Tabs
  • Types of wait statement in selenium
  • How to take screenshots?
  • How to upload File in Selenium?
  • How to handle scroll function using JavaScriptExecutor?
  • How to handle basic functionality using JavaScriptExecutor?
  • How to handle advanced functionality using JavaScriptExecutor?
  • How to automate CAPTCHA?
  • How to handle cookies in selenium
View Categories
  • Home
  • Tutorials
  • Selenium Automation
  • Selenium Automation Testing
  • Handling Images

Handling Images

Handling Images

Verifying images and logos in Selenium automation can mean a few different things, depending on your test requirement. Here are the most common scenarios and how you can automate each one in Selenium:

1. Verify Image or Logo is Displayed

Check if the image element is present and visible on the page.

WebElement logo = driver.findElement(By.id("companyLogo"));

if (logo.isDisplayed()) {

    System.out.println("Logo is displayed!");

} else {

    System.out.println("Logo is NOT displayed!");

}

2. Verify the Image Source (src Attribute)

Check that the image source URL is correct (for branding or dynamic images)

String logoSrc = logo.getAttribute("src");

if (logoSrc.equals("https://yourwebsite.com/images/logo.png")) {

    System.out.println("Logo src is correct!");

} else {

    System.out.println("Logo src is NOT correct!");

}

3. Verify Image Loads Properly (Not Broken)

Check if the image actually loads (not just present in HTML), by validating the naturalWidth property using JavaScript.

Boolean imageLoaded = (Boolean) ((JavascriptExecutor)driver).executeScript(

    "return arguments[0].complete && " +

    "typeof arguments[0].naturalWidth != 'undefined' && " +

    "arguments[0].naturalWidth > 0", logo);

if (imageLoaded) {

    System.out.println("Logo is loaded successfully!");

} else {

    System.out.println("Logo is broken or not loaded!");

}

4. Verify Image Alt Attribute (Accessibility Testing)

Ensure alt text is present and correct for accessibility.

String altText = logo.getAttribute("alt");

if (altText.equals("Your Company Logo")) {

    System.out.println("Alt text is correct!");

} else {

    System.out.println("Alt text is missing or incorrect!");

}

5. (Advanced) Verify Image Pixels/Visual Match

If you need to verify that the image looks exactly as expected (pixel match), Selenium alone is not enough.
You need to:

  • Take a screenshot of the image or logo.
  • Compare it with a baseline/reference image using tools like Ashot, Sikuli, or integrate with image comparison libraries.

Example using Ashot library:

// Not pure Selenium: add Ashot dependency to project first

Screenshot imageScreenshot = new AShot().takeScreenshot(driver, logo);

// Compare imageScreenshot.getImage() with your baseline image

Summary Table

Verification TypeHow to Check
Image is displayedisDisplayed()
Image source is correctgetAttribute(“src”)
Image loads (not broken)JavaScript: check naturalWidth > 0
Image alt attributegetAttribute(“alt”)
Visual (pixel) matchUse Ashot, Sikuli, or external comparison tools
Selenium Automation Testing
What are your Feelings
Share This Article :
  • Facebook
  • X
  • LinkedIn
© 2018 – 2025 Vinoth Tech Solutions Ltd (UK), Reg. No: 16489105