How To Handle Images in Selenium Webdriver using Java

           Handling Images in Selenium webdriver

In this tutorial we are going to learn how to handle images in selenium webdriver . Image links in web pages are the links that represent an image and it navigate user to other page or browser windows when user click on images .While automating images we can not use link text and partial link text locator because images has no link text .In Selenium webdriver an image can be locate or selected by id, name, className, cssSelector, xpath etc

1- How to click on image in selenium webdriver?
To click on an image in selenium use click() method .

Selenium Code -
Selenium code to click on image using click method.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
 
public class HandlingImage {
 
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Software\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.amazon.in/");

//Below code will locate the images and click on images.
driver.findElement(By.xpath("//a[@id='nav-logo-sprites']")).click();

System.out.println("clicked successfully");
 
}
 
}
Above selenium code will first launch the chrome browser then navigate to amazon site then it will locate the image using xpath and then it will click on image and print the message on console.

2-How to check if an image is displayed on page using Selenium?

3- How to find broken Images using Selenium Webdriver ?

not Completed Yet...



Hope !!! Above Tutorial of handling images in selenium helpful for you ...

Team ,
QA acharya 

Tags: how to handle image in selenium , Selenium images , How to Click on images in selenium , Image Handling in selenium 

How to Handle Images In Selenium Webdriver


Admin-Mumbai office

Post a Comment

Previous Post Next Post