1

trying to click a input type using selenium python, input type calls image file, and added css cursor: pointer on the image, unfortunately cant click the image or the input

Image

enter image description here

Code

<input type="image" src="/images/btn_next.png">

CSS

input[type="image" i] 
{
    cursor: pointer;
}

how to click on the image "Next Step" ?

I tried, but shows error

driver.find_element_by_xpath('//input[@type="image"][@src="/images/btn_next.png"]').click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Harry Edward
  • 141
  • 2
  • 2
  • 14

3 Answers3

2

Try Use WebdriverWait and element_to_be_clickable to click on the image.

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

WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,'//input[@type="image"][@src="/images/btn_next.png"]'))).click()

If above code unable to click on the element try use javaScript executor to click on the element.

driver.execute_script("arguments[0].click();",driver.find_element_by_xpath('//input[@type="image"][@src="/images/btn_next.png"]'))
KunduK
  • 32,888
  • 5
  • 17
  • 41
1

You were close. To click() on the element you need to club up the attributes within the xpath using and and you can use either of the following Locator Strategies:

  • Using css_selector:

    driver.find_element_by_css_selector("input[src='/images/btn_next.png'][type='image']").click()
    
  • Using xpath:

    driver.find_element_by_xpath("//input[@src='/images/btn_next.png' and @type='image']").click()
    

But as you intend to invoke click() on the element, ideally you need to induce WebDriverWait for the element_to_be_clickable() as follows:

  • Using css_selector:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[src='/images/btn_next.png'][type='image']"))).click()
    
  • Using xpath:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@src='/images/btn_next.png' and @type='image']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-1

If you run chrome then probably moving physical cursor to image and click can help. There is python package that move physical cursor to web element, selenium-move-cursor.

smirad91
  • 19
  • 1
  • 4