Using Selenium Web Driver to retrieve value of a HTML input

0
0

In the HTML of a webapp there is the following code

<input type="text" name="prettyTime" id="prettyTime" class="ui-state-disabled prettyTime"  readonly="readonly">

What is actually shown on the page is a string displaying the time.

In Selenium Web Driver, I have a WebElement object referring to the <input> using

WebElement timeStamp = waitForElement(By.id("prettyTime"));

I want to get the value of the WebElement, or, in other words, what is printed on the page. I tried all the WebElement getters and nothing has been retrieving the actual value that the user sees. Any help? Thanks.

  • You must to post comments
0
0

Try element.getAttribute("value")

The text property is for text within the tags of an element. For input elements, the displayed text is not wrapped by the <input> tag, instead it’s inside the value attribute.

Note: Case matters. If you specify “Value”, you’ll get a ‘null’ value back. This is true for C# at least.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website