Selenium WebDriver for retrieving HTML input value

0 votes

Following code is the HTML of a page. 

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

The display on the page is simply a string displaying time.
In WebDriver, there is a WebElement object referring to <input> tag using

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

I want the value of the element (what ever is displayed on the page). I tried every WebElement getters and nothing is useful for retrieving the value that the user sees. Any help? Thanks.

May 23, 2018 in Selenium by abc_xyz
36 views

1 answer to this question.

0 votes

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.

answered May 23, 2018 by sniffy_god
• 760 points

Related Questions In Selenium

0 votes
1 answer

Selecting a dropdown value in Selenium WebDriver

Try to wrap your WebElement as shown ...READ MORE

answered Apr 9, 2018 in Selenium by QueenBee
• 1,810 points
796 views
0 votes
1 answer

Locating an element by value using css selector using Selenium WebDriver

Below code will help By.cssSelector("td[class='someclass'][value='u ...READ MORE

answered Apr 9, 2018 in Selenium by coldcode
• 2,010 points
86 views
0 votes
1 answer

Using gettext() method for the specific element using Selenium WebDriver

Mistake is that u r printing the ...READ MORE

answered Apr 10, 2018 in Selenium by Vardy
• 2,280 points
3,972 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
280 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
641 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
269 views
0 votes
2 answers
0 votes
2 answers