How to click on an image in Selenium Python?

Selenium Python – Click on an image

In this tutorial, you shall learn how to make click action on an image element, using Selenium in Python language.

To click on a given image element in Selenium Python, you can use the method. Get the image element, and call the click() method on the image element object.

This operation is usually used in scenarios where clicking on an image executes a specific JavaScript function, or makes the image bigger, or something like that.


In the following examples, we shall consider loading the HTML file at path . The contents of this HTML file is given below.

    <h3>Hello World</h3> 
    <img id="image1" src="" alt="My sample image 1">
    <img id="image2" src="" alt="My sample image 2">
    <img id="image3" src="" alt="My sample image 3" hidden>

1. Click on image with id=”image1″

In the following program, we initialize a driver object, load the specified URL, find the image element with id=”image1″, and make a click action on this image element.

Python Program

from selenium import webdriver
from import Service as ChromeService
from import ChromeDriverManager
from import By

# Setup chrome driver
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

# Navigate to the url

# Find the image
image_1 = driver.find_element(By.ID, 'image1')

# Click on image
print('Clicked on image.')

# Close the driver


Clicked on image.


In this Python Selenium tutorial, we have seen how to click on an image element in a webpage using Selenium, with example programs.

Related Tutorials

Quiz on Selenium

Q1. What is a web driver in Selenium Python?

Not answered

Q2. Which of the following is not a method to wait for a web element to load in Selenium Python?

Not answered

Q3. What is the method used to navigate back to the previous page in Selenium Python?

Not answered

Q4. What is the method used to switch to a different frame in Selenium Python?

Not answered

Q5. What is the method used to clear the text from an input field in Selenium Python?

Not answered
Code copied to clipboard successfully 👍