Home > database >  Python Selenium, Input field returns an ElementNotInteractableException even though element is inter
Python Selenium, Input field returns an ElementNotInteractableException even though element is inter

Time:10-28

SOLVED:

It seems like this single input field would be not interactable unless it was clicked in the most recent 0.1 seconds. To solve that the following code was used:

ActionChains(self.driver).move_to_element(input).click().send_keys("200").perform()

This way the focus stays on the element and the input works. Interestingly, if input.send_keys() is called this still does not work.

Problem:

After pressing a button on the website, a popup window opens up which contains multiple input fields which are generated by react. Most of these are accessible. However, one of them is not and returns an ElementNotInteractableException error. I have tried the most common solutions but those do not work.

The interesting part is that when the element is accessed manually from the front end, it can be interacted with. The element also is shown normally in a screenshot which is taken upon an exception being thrown

Solutions tried:

  • Increase implicit wait until 1 minute,
  • Add explicit wait untill 1 minute
  • Use different finding methods for the element
  • Reorder test to see if other elements influence it (all possible orders have failed)
  • Add Actionchains Move to and Click. The move to and click work (I can see the element being selected with a blue outline, but the input still feels)
  • Use Javascript to insert the string into the input fields.value

Code block on which the error occurs:

    #this input element is next to it in the same parent element
    dropdownparent = elems[2].find_element_by_xpath(".//div[@role='combobox']")
    dropdowninput = dropdownparent.find_element_by_css_selector("input")
    f.inputtext(dropdowninput, "Coulance", True )
    #reobtain the parent items to avoid a stale element reference error
    modal = self.driver.find_element_by_class_name("component-window")
    body = modal.find_element_by_class_name("body")
    elems = body.find_elements_by_xpath("./div")
    required = elems[2].find_elements_by_class_name("required")
    inputparent = required[1].find_element_by_class_name("input")
    input = inputparent.find_element_by_css_selector("input")
    #error occurs on next line
    f.inputtext(input, "200")

Error log:

https://pastebin.com/ihqCvjfj

its long but its a very standard elementnotaccessible

Any suggestions would be appreciated, I will update the solutions tried section whenever I try something

CodePudding user response:

Element not interactable comes when the element is out of clickable area or some other element is covering up that element. You can try by scrolling the page to an element or you can set input value by executing javascript, something like this:

element = inputparent.find_element_by_css_selector("input")
driver.execute_script("""arguments[0].value = arguments[1];""", element, "some input value") 
  • Related