Selenium is an open-source web-based automation tool. In this answer, we will learn how to click on an image using Selenium Webdriver in Python.
First, we will find the image present in the DOM and click the image using the click()
method.
image_element.click()
It doesn't take any parameters and won't return anything.
from selenium import webdriverimport time#specify where your chrome driver present in your pcPATH=r"C:\Users\gutkrish\Documents\chromedriver\chromedriver.exe"#get instance of web driverdriver = webdriver.Chrome(PATH)#provide website url heredriver.get("http://demo.guru99.com/test/newtours/")#locate image element and click itdriver.find_element("tag name","img").click()
webdriver
from the selenium
package.time
.chromedriver.exe
in the windows environment.webdriver
.driver.get()
method to open it.click()
method on that element.