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 the selenium web driver. Image links in web pages are the links that represent an image and they navigate the user to other pages or browser windows when the user clicks on images. While automating images we can not use link text and partial link text locator because images have no link text. In Selenium web driver an image can be located or selected by id, name, className, CSS selector, XPath etc

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

Selenium Code -
Selenium code to click on the image using the 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, the code will first launch the chrome browser then navigate to the amazon site then it will locate the image using XPath and then it will click on the image and print the message on the console.

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

3- How to find broken Images using Selenium Webdriver?

not Completed Yet...



Hope !!! The above Tutorial on handling images in selenium is helpful for you ...

Team,
QA acharya 

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

How to Handle Images In Selenium Webdriver


.

Post a Comment

0 Comments