3

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
  • What exactly are you trying to achieve? Changing the contents of an input via the UI doesn't change the underlying value attribute. Commented Dec 4, 2017 at 13:11
  • Yes, figured that out. Thanks @DebanjanB. I am trying to change the contents of a search input tag. The website(web.whatsapp) is using react.js. I am trying to search by name using the field. Commented Dec 4, 2017 at 15:26

2 Answers 2

5

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

1

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.