'Filling out create form with values from a list/dict using webdriver
I've located all inputs on a create form with on my application by:
_inputs =find_elements_by_xpath("//form[@id='createForm']//input")
and I got my list of values that I need to input :
_data = ['selenium', 'selenium test', 'John Dow']
what I'd like to do is to send keys to each of those webelements from list using a loop, what I wrote
for x in range(len(self._data)):
try:
_inputs[x].send_keys(self._data[x])
except Exception:
continue
finally:
_all_inputs[0].send_keys(Keys.RETURN)
sending RETURN should trigger the submission of the form
but I'm getting selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
When I'm sending keys individually it's not an issue but well that's not what I'm trying to do here.
Solution 1:[1]
You can use visibility_of from expected_conditions
to make sure the element is visible
wait = WebDriverWait(driver, 10)
for x in range(len(self._data)):
try:
wait.until(expected_conditions.visibility_of(_inputs[x]))
_inputs[x].send_keys(self._data[x])
except Exception:
continue
finally:
_all_inputs[0].send_keys(Keys.RETURN)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Guy |