0

When I type in a text input box without pressing enter, the text is displayed in the textbox but is not set to the input element's value attribute in the html. It doesn't show up in the input tag or anywhere in the html of the page until I press enter.

How does this work? Doesn't all text showing up on the screen need to be in the html in some form even if the html is dynamically generated?

Is there any way to test for the presence of the inputted text in the html using xpath or any other method, prior to submitting and updating the value attribute?

Any help or insight on how this works would be much appreciated.

Textbox input

A. J. Green
  • 93
  • 2
  • 8
  • 1
    It is stored programmatically instead: if you query the element and access its `value` attribute, you should see that. The `value` attribute in the DOM only reflects the initial value and is not dynamically updated: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-value – Terry Jan 16 '22 at 20:46
  • @Terry It doesn't seem like the value can be retrieved by selenium which I thought was querying the element. Is this what you mean by querying? document.getElementById("inputBox1").value – A. J. Green Jan 16 '22 at 21:05
  • 1
    If you’re using selenium perhaps it’s useful to mention it in your question: otherwise it’s be easily mistaken that you’re attempting to do it in a browser. Have you looked at this question? https://stackoverflow.com/questions/7852287/using-selenium-web-driver-to-retrieve-value-of-a-html-input – Terry Jan 16 '22 at 22:20
  • @Terry Thank you for the link. I avoided mentioning Selenium because I was trying to get a better understanding of what's happening rather than just getting Selenium to work. I think I do understand now. The issue I was having is to attempt to select element using xPath in selenium based the text entered, which does not appear to be possible until the DOM is updates the value attribute. Selecting all input text boxes and then querying each one to see if they contain the right value is one option. – A. J. Green Jan 16 '22 at 22:36

0 Answers0