- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Using Selenium Web Driver to retrieve value of a HTML input.
We can get the value of a HTML input with Selenium webdriver. This is achieved with the help of the getAttribute() method. To retrieve the value of the field with tagname input, we have to pass the value as parameter to the getAttribute() method.
Let us consider an html code for a html input.
We have no value attribute for the field in the DOM. However we shall get the field value as displayed with getAttribute() method.
Example
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class InputVal{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); // identify element and enter text WebElement l = driver.findElement(By.id("gsc-i-id1")); l.sendKeys("Selenium"); // getAttribute() to get value as displayed in GUI String val = l.getAttribute("value"); System.out.println("The input value: "+ val); driver.quit() } }
Output
- Related Articles
- How to set “value” to input web element using selenium?
- Get text using selenium web driver in python?
- What is selenium web driver?
- What is Web Driver in Selenium?
- How to run selenium (Firefox) web driver without a GUI?
- Difference between selenium RC and Web Driver?
- What is the Selenium Web Driver Architecture?
- How to get userAgent information in Selenium Web driver?
- Gecko driver, Selecting value from a dropdown list using Selenium
- How to get text with selenium web driver in python?
- How to use Selenium Web Driver and JavaScript to Login any website?
- Get value of an input box using Selenium (Python)
- Is it possible to manually set the attribute value of a Web Element using Selenium?
- How to get the attribute value of a web element in Selenium (using Java or Python)?
- Which programming language is better for writing Selenium web driver scripts, Python or Java?

Advertisements