0

I'm struggling with an automation task where the HTML site has an input field, but when I search it out in DOM Explorer it looks like this:

<input name="txtFirewall" id="txtFirewall" type="text">

As you can see, there is no value attribute. Once you give in smthing manually to the search field it changes like this:

<input name="txtFirewall" id="txtFirewall" type="text">value="Something">

How can I add the Value attribute and assign value to it with python? Can it be even done with Selenium?

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Mark
  • 83
  • 1
  • 1
  • 7
  • There was nothing useful here? https://www.google./search?q=add+value+attribute+selenium ? I see several interesting links – mplungjan Nov 30 '17 at 12:11
  • 2
    `'element = driver.find_element_by_css_selector("txtFirewall")` and then `driver.execute_script("arguments[0].setAttribute('value','whatever')", element)'` according to this https://stackoverflow.com/questions/817218/how-to-get-the-entire-document-html-as-a-string – mplungjan Nov 30 '17 at 12:15

2 Answers2

1

This code can help you:

search_field = driver.find_element_by_id("txtFirewall")
search_field.send_keys("Something")

Hope it helps you!

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
0

To add the value attribute and assign the value 'Something' to it you can use the following code block :

element = driver.find_element_by_css_selector("input#txtFirewall.txtFirewall")
driver.execute_script("arguments[0].setAttribute('value','Something')", element)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352