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)`   
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)
Sign up to request clarification or add additional context in comments.

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)

Comments

Your Answer

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.