- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 typed text from a textbox by using Selenium Webdriver?
We can get the typed text from a textbox with Selenium webdriver. Firstly, we have to enter text in the text box (after being identified with any locators) with the help of the sendKeys method.
Then apply the method getAttribute to obtain the text entered in that field and pass the parameter value to that method. Let us make an attempt to obtain the value entered in the Google search box −
Syntax
WebElement m = driver.findElement(By.name("q")); String st = m.getAttribute("value");
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class GetTextTyped{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); //implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("https://www.google.com/"); // identify element WebElement t =driver.findElement(By.name("q")); t.sendKeys("Tutorialspoint"); // obtain value with getAttribute System.out.println("Value is: " + t.getAttribute("value")); driver.quit(); } }
Output
- Related Articles
- How to get entered text from a textbox in selenium?
- How can I clear text of a textbox using Python Selenium WebDriver?
- How to get Tooltip Text in Selenium Webdriver?
- How to type in textbox using Selenium WebDriver with Java?
- How to get the text from a website using selenium?
- How to send keyboard input to a textbox on a webpage using Python Selenium webdriver?
- How to get HTTP Response Code using Selenium WebDriver?
- How to get all options in a drop-down list by Selenium WebDriver using C#?
- How to capture the text from Alert Message in Selenium Webdriver?
- How to get selected option using Selenium WebDriver with Java?
- How to get selected option using Selenium WebDriver with Python?
- How to get all options of a dropdown using Python Selenium webdriver?
- How to Select Value from DropDown using Selenium Webdriver?
- How to get text from Selenium element WebElement object?
- How to get text from each cell of an HTML table using Selenium?

Advertisements