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)`
undetected Selenium
194k44 gold badges304 silver badges387 bronze badges
asked Dec 4, 2017 at 13:05
2 Answers 2
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)
answered Dec 4, 2017 at 13:19
Comments
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)
answered Jan 22, 2019 at 15:19
Comments
Explore related questions
See similar questions with these tags.
default
value
attribute.