简体   繁体   中英

Not able to click using selenium python webdriver

Not able to click button

<p>
    <img class="getdata-button" style="float:right;" src="/common/images/btn-get-data.gif" id="get" onclick="document.getElementById('submitMe').click()">  
    <input type="button" value="Get Results" tabindex="9" id="submitMe" onclick="submitData();" style="display:none" ;="">
</p>

Case-1.

sub_driver.find_element_by_xpath("//img[@class='getdata-button']").click()

session goes into like hung state (not actually), but nothing happened.

Case-2

sub_driver.find_element_by_xpath("//img[@class='getdata-button']").click()

throws error like: Element not interactable

For clicking the button, you can do it by the id:

button = driver.find_element_by_id("submitMe")
button.click()

Please refer below solution:

using ActionChain

button_actual=WebDriverWait(driver, 30).until(
            EC.element_to_be_clickable((By.ID, "submitMe")))

actionChains.move_to_element(button_actual).click().perform()

or

Using Javascript click

button_actual=WebDriverWait(driver, 30).until(
            EC.element_to_be_clickable((By.ID, "submitMe")))
driver.execute_script("arguments[0].click();", button_actual)

Note: please add below imports to your solution

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM