- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to click on image in selenium webdriver Python?
We can click on an image with Selenium webdriver in Python using the method click. First of all, we have to identify the image with the help of any of the locators like id, class, name, css, xpath, and so on. An image in the html code is represented by the img tagname.
Let us see the html code of an image element.
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class ImageClk{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); //implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("https://www.tutorialspoint.com/index.htm"); // identify image WebElement l = driver.findElement(By.xpath("//img[@alt='Tutorialspoint']")); String s = l.getAttribute("title"); System.out.println("Title attribute value is :" + s); l.click(); driver.quit(); } }
Output
- Related Articles
- How to click on a link using Selenium webdriver in Python.
- How to click on hidden element in Selenium WebDriver?
- How to click on across browsers using Selenium Webdriver?
- How to click Allow on Show Notifications popup using Selenium Webdriver?
- Selenium Webdriver submit() vs click().
- How to use Selenium webdriver to click google search?
- How to click on a link in Selenium with python?
- How do you click on an element which is hidden using Selenium WebDriver?
- How to click button Selenium Python?
- How to click on a link in Selenium?
- How to perform double click on an element in Selenium with python?
- How to perform right click on an element in Selenium with python?
- How to click on a button with Javascript executor in Selenium with python?
- How to install Selenium WebDriver on Mac OS?
- How to perform double click on an element in Selenium?

Advertisements