Using Selenium Web Driver to retrieve value of a HTML input (Java)

Using Selenium Web Driver to retrieve value of a HTML input (Java)

To get the text entered into an input element, use element.getAttribute("value") where element is the input element. The attribute text is used to get the text from the tags within an element.

WebElement query = driver.findElement(By.id("searchInput"));
query.sendKeys("the moon");

System.out.println(query.getAttribute("value"));

Leave a reply

Your email address will not be published. Required fields are marked*

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.