Check whether element is clickable in selenium

后端 未结 3 1415
孤独总比滥情好
孤独总比滥情好 2020-12-10 12:36

I\'m able to verify whether or not an element exists and whether or not it is displayed, but can\'t seem to find a way to see whether it is \'clickable\' (Not talking about

相关标签:
3条回答
  • 2020-12-10 12:56

    You can wait for the element to be clickable:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    driver = webdriver.Firefox()
    driver.get("http://somedomain")
    
    element = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.ID, "myDynamicElement"))
    )
    

    Or, you can follow the EAFP principle and catch an exception being raised by click():

    from selenium.common.exceptions import WebDriverException
    
    try:
        element.click()
    except WebDriverException:
        print "Element is not clickable"
    
    0 讨论(0)
  • 2020-12-10 13:08

    to click an (for selenium) unreachable element i alwas use:

    public void clickElement(WebElement el) throws InterruptedException {
        ((JavascriptExecutor) driver).executeScript("arguments[0].click();", el);
    }
    
    0 讨论(0)
  • 2020-12-10 13:13

    You can use webElement.isEnabled() and webElement.isDisplayed() methods before performing any operation on the input field...

    I hope this will solve you problem...

    Else, you can also put a loop to check above 2 conditions and if those are true you can specify the input text and again you can find the same element and you can get the text of the webelement and compare that text with the text you entered. If those matches you can come out of the loop.

    0 讨论(0)
提交回复
热议问题