How can I solve the issue of “ElementNotInteractableException” in selenium?

290    Asked by Unnatigautam in QA Testing , Asked on Jan 5, 2024

 I am in a scenario where I am trying to automate a web application by using selenium, however during the process i encountered an issue that was telling “ElementNotInteractableException”. How can I troubleshoot this particular issue? 

Answered by Charles Parr

While getting the error message of “ElementNotInteractableException” in the selenium during the process of interacting with a button on a webpage, then it usually refers that the element you are trying to interact with is presented in the DOM however it is not a state which can allow interactions for you.

To handle this particular issue here are the steps given below:-

Wait for interactability

Wait for the intractability of the elements to become clickable before performing further action. This can be done using conditions such as :

From selenium.webdriver.common.by import By

From selenium.webdriver.support.ui import WebDriverWait

From selenium.webdriver.support import expected_conditions as EC

# Wait for the element to be clickable

Element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, ‘element_id’)))

Element.click() # Perform the action once the element is clickable

Scroll into view

If the element is not interactable because the element is not in the visible area, then use JavaScript to scroll the element for viewing:

Element = driver.find_element_by_id(‘element_id’)
Driver.execute_script(“arguments[0].scrollIntoView(true);”, element)
Handle overlapping elements
Ensure that the element should not overlap with other elements.
Check element state
Ensure that the element is displayed, or hidden before performing further actions.
Element = driver.find_element_by_id(‘element_id’)
If element.is_displayed() and element.is_enabled():

    Element.click() # Perform the action if the element is displayed and enabled



Your Answer

Interviews

Parent Categories