How to click on Image in Selenium Webdriver?

0 votes
May 9 in Selenium by Lalit
86 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 by Anvi
• 10,750 points

Related Questions In Selenium

0 votes
1 answer
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 in Selenium by Abha
• 16,980 points
70 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 in Selenium by anonymous
10 views
0 votes
3 answers

How to specify "ENTER" button functionality in Selenium WebDriver code?

using OpenQA.Selenium.Interactions; Actions builder = new Actions(driver); ...READ MORE

answered Feb 12 in Selenium by anonymous
6,454 views
0 votes
1 answer

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,050 points
272 views
0 votes
1 answer
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,130 points
639 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
264 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 6 hours ago in Selenium by Anvi
• 10,750 points
7 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 in Selenium by Anvi
• 10,750 points
47 views