Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

In the HTML of a web app, 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 WebElementor, 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. 

1 Answer

0 votes
by (62.9k points)

 The following code is what I use in Selenium 2.0:

WebElement element = driver.findElement(By.id("input_name")); String elementval = element.getAttribute("value");

OR

String elementval = driver.findElement(By.id("input_name")).getAttribute("value");

Hope this was helpful.


 

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...