Reputation: 31
The following html tag:
<input id="input-value" title="Search" type="text" value="">
I want to change the value attribute from "" to "foo".
<input id="input-value" title="Search" type="text" value="foo">
I am trying this with send_keys()
with no success.
ele = browser.find_element_by_id("input-value")
ele.send_keys("foo")
ele.send_keys(Keys.RETURN)`
Upvotes: 3
Views: 11416
Reputation: 11
Using .click() before .send_keys() like:
ele = browser.find_element_by_id("input-value")
ele.click()
ele.send_keys("foo")
ele.send_keys(Keys.RETURN)
Upvotes: 1
Reputation: 193088
To edit the value
attribute and assign the value foo
to it you can use the following code block which uses the JavascriptExecutor :
ele = browser.find_element_by_css_selector("input#input-value")
browser.execute_script("arguments[0].setAttribute('value','foo')", ele)
Upvotes: 5