OneMore
OneMore

Reputation: 99

Python Selenium Click Image

I'm new to Python and I want to click on the image here. I know how to click a button, but I can't do it for the image.

<img src="./img/icon/tema-icon-1-03.png" alt="imgAlt">

What I did for the button

login_box = driver.find_element_by_xpath("//*[@type='submit']")

The part I made for the button works great

Here is what I tried but it didn't work

appointment_image = driver.find_element_by_xpath("//img[contains(@src='./img/icon/tema-icon-1-03.png')]").click()

Upvotes: 1

Views: 902

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

if this is Unique in DOM :-

<img src="./img/icon/tema-icon-1-03.png" alt="imgAlt">

you can click on it using:

driver.find_element_by_xpath("//img[contains(@src, '/img/icon/tema') and @alt = 'imgAlt']")

or

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//img[contains(@src, '/img/icon/tema') and @alt = 'imgAlt']"))).click()

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Upvotes: 1

Related Questions