How to click on Image in Selenium Webdriver

0 votes
May 9, 2019 in Selenium by Lalit
6,952 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,130 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
4,657 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,000 points
5,088 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
199 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,520 points
4,630 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,010 points
5,474 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,890 points
3,303 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 2, 2020 in Selenium by Sri
• 3,010 points
3,904 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 22, 2019 in Selenium by Anvi
• 14,130 points
1,141 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,130 points
4,205 views