- 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
How to get entered text from a textbox in selenium?
We can get the entered text from a textbox in Selenium webdriver. To obtain the value attribute of an element in the html document, we have to use the getAttribute() method. Then the value is passed as a parameter to the method.
Let us consider a textbox where we entered some text and then want to get the entered text.
If we spy on the element, we will find that there is no value attribute for this element in the html code.
After entering text inside that field, we can get the entered text by using the getAttribute() method.
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class GetValAttribute{ 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 WebElement l = driver.findElement(By.id("gsc-i-id1")); // enter texts l.sendKeys("Selenium"); // get value attribute with getAttribute() String val = l.getAttribute("value"); System.out.println("Entered text is: " + val); driver.quit() } }
Output
- Related Articles
- How to get typed text from a textbox by using Selenium Webdriver?
- How to clear the text entered in Selenium with python?
- How to get the text from a website using selenium?
- How to get text from Selenium element WebElement object?
- How can I clear text of a textbox using Python Selenium WebDriver?
- How to get Tooltip Text in Selenium Webdriver?
- How to get text found between span – Selenium
- How to get text from each cell of an HTML table using Selenium?
- How to get text with selenium web driver in python?
- How to extract text from a Javascript alert in Selenium with python?
- How to type in textbox using Selenium WebDriver with Java?
- How to set the alignment of text in a Textbox using FabricJS?
- How to get a new API response in a Tkinter textbox?
- How to capture the text from Alert Message in Selenium Webdriver?
- How to get attribute of element from Selenium?

Advertisements