Search code examples
pythonseleniumselenium-webdriverwebdriverwaitexpected-condition

Selenium Expected Conditions, Wait until element is interactable?


Is there a way to get around the elementNotInteractable exception in selenium? I've used

wait.until(ec.element_to_be_clickable())

But my code will still try to interact with elements before they're fully interactable. Is the problem that I just haven't set the delay high enough when defining wait? Or is there a function like

ec.element_to_be_interactable()

which checks if the element is interactable or not?


Solution

  • element_to_be_clickable()

    element_to_be_clickable() is the expectation for for checking if an element is visible and enabled so that you can click() it.


    ElementNotInteractableException

    Unfortunately there is no specific expected_conditions as ElementNotInteractableException and it can occur for a lot of reasons and some of them are:

    • Lower Timeout interval. In these cases you have to increase the timeout as follows:

      wait = WebDriverWait(driver, 20)
      
    • Selecting and invoking click() the outer/parent element rather then the child element.

    • A typical scenario is targetting the <input> where there is a related <label> element.