- 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 extract the text of a webelement in Selenium?
Selenium extracts the text of a webelement with the help of getText() method.
Code Implementation with getText().
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 ExtractText { 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(12, TimeUnit.SECONDS); //Using id with # for css expression driver.findElement(By.cssSelector("#gsc-i-id1")).sendKeys("Selenium"); // extracting the text entered in console with getText() System.out.println(“The entered text is:” driver.findElement(By.cssSelector("#gsc-i- id1")).getText()); driver.close(); } }
- Related Articles
- How to get text from Selenium element WebElement object?
- How to get HTML code of a WebElement in Selenium?
- How to extract text from a Javascript alert in Selenium with python?
- How to fetch values from a webelement in Selenium with python?
- How to scroll a Web Page using coordinates of a WebElement in Selenium WebDriver?
- How to extract text from a web page using Selenium and save it as a text file?
- Can I set any of the attribute value of a WebElement in Selenium?
- Get HTML Source of WebElement in Selenium WebDriver using Python.
- How to extract the attribute value of an element in Selenium?
- How to select the text of a span on click in Selenium?
- How to extract the column headers in a table in Selenium with python?
- How to extract only the numbers from a text field in MySQL?
- How to get the text from a website using selenium?
- How to input text in the text box without calling the sendKeys() using Selenium?
- How to get entered text from a textbox in selenium?

Advertisements