How to click on Image in Selenium Webdriver

0 votes
May 9, 2019 in Selenium by Lalit
12,564 views

1 answer to this question.

0 votes

Hello Lalit, I guess you mean to say clicking an image on a web page using Selenium Webdriver. So to click an image using selenium webdriver, you can try this piece of code: 

package clickImageProject;
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver;  

public class ClickImage{    

    public static void main(String[] args) {        
        String Url = "https://www.edureka.co/devops-certification-courses";    
        System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");    
        WebDriver driver = new ChromeDriver();     

        driver.get(Url);    
        //click on the "Edureka" logo on the upper left portion 
   driver.findElement(By.Xpath("//i[@class='icon-logo edu-logo-style']")).click();    
   //verify that we are now back on Edureka's homepage 
   if (driver.getTitle().equals("Instructor-Led Online Training with 24X7 Lifetime Support | Edureka")) {      
            System.out.println("We are back at Edureka's homepage");    
        } else {  
            System.out.println("We are NOT on Edureka's homepage");    
        } 
    driver.close();  

    } 
}

Now, in the code above, I have used Xpath to get the image location, but you can also use CSS selector.

answered May 9, 2019 by Anvi
• 14,150 points

Related Questions In Selenium

0 votes
1 answer

How to check if an image is displayed on web page while working with Selenium WebDriver?

I've come across a similar situation before, where the image ...READ MORE

answered May 10, 2019 in Selenium by Surya
• 970 points
7,925 views
0 votes
1 answer

How to click on a hyperlink using Selenium WebDriver?

Hi Jonathan, you can use click() method in ...READ MORE

answered May 29, 2019 in Selenium by Abha
• 28,140 points
7,239 views
0 votes
0 answers

How to click an image in gmail using selenium

The image in the body of the ...READ MORE

Jul 13, 2019 in Selenium by anonymous
1,179 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,674 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,143 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
0 votes
1 answer

How to automate radio button and checkbox on a webpage in Selenium Webdriver?

Hey Yashmita, following code snippet automates the ...READ MORE

answered Jul 23, 2019 in Selenium by Anvi
• 14,150 points
2,353 views
0 votes
1 answer

How to mouse hover on a web element using Selenium WebDriver?

Hello Nitin, to automate mouse hovering over ...READ MORE

answered May 7, 2019 in Selenium by Anvi
• 14,150 points
6,518 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP