Italian Trulli

How To Handle Images in Selenium Webdriver using Java

Test Tribe
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 the Selenium web driver, an image can be located or selected by id, name, className, CSS selector, XPath, etc.

How To Click On The Image in Selenium Webdriver?
To click on an image in selenium use the click() method.

Selenium code to click on the image using the click method.

Selenium Code 

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

//Below code will locate the images and click on images.

System.out.println("clicked successfully");
Code Explanation
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.

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

Javascript Executor
In Selenium Webddiver we can check if an image is displayed on the page. To verify an image we shall take the help of a Javascript Executor.

How to find broken Images using Selenium Webdriver?

not Completed Yet...

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

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