How to click on Image in Selenium Webdriver?

0 votes
May 9 in Selenium by Lalit
21 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 5,960 points

Related Questions In Selenium

0 votes
1 answer
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
4,518 views
0 votes
1 answer

Python & Selenium: How to find and click on YouTube's Like button

Use the CSS Selector button to like: #watch8-sentiment-actions ...READ MORE

answered Mar 26, 2018 in Selenium by nsv999
• 5,030 points
433 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
1,233 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,030 points
72 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
445 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
55 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
• 5,960 points
15 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.