Reputation: 4045
I solved it by doing a find_elements_by_xpath
and then using a try, catch
for all elements till no error and break.
Getting an error when trying to click
or send_keys
to an input
element.
st = driver.find_element_by_xpath('//input[contains(@id, "st")]')
# Element found
st.send_keys(str(amt))
# Error element not interactable
st.click()
# error element not interactable
The element:
<input id="st" type="text" value="" maxlength="7" tabindex="0">
I am able to interact and send keys to another element in the same row as this on the webpage.
Traceback:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Volumes/coding/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/Volumes/coding/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/Volumes/coding/venv/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Volumes/coding/venv/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=90.0.4430.72)
Any idea on how to solve or why I am running into this error?
Upvotes: 1
Views: 292
Reputation: 74
Don't know the exact reason why the element is not interacting but you can add text to input box using JavaScript. There is a class in Selenium which allows to execute JavaScript code in browser. Do somethin like this:
script = "arguments[0].value="+str(amt)
driver.execute_script(script,st)
driver.execute_script("arguments[0].click()",st)
This will set the value of input box to the given string.
In C#:
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
string script = "arguments[0].value="+amt.toString();
js.executeScript(script,st)
//to click
js.executScript("arguments[0].click()",st)
Hope it will work.
Upvotes: 1