- 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 the value of the edit box in Selenium?
We can get the value of the edit box in Selenium by the following ways −
By using getText () method.
Using the class JavascriptExecutor.
Code Implementation with method 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 GetValueScripting { 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); String text = driver.findElement(By.className("gsc-input")).getText(); System.out.println("Extracted text is " + text); driver.close(); } }
Code Implementation with class JavascriptExecutor.
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; import org.openqa.selenium.JavascriptExecutor; public class ExtractValueScripting { 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); // create Javascript object JavascriptExecutor js = (JavascriptExecutor)driver; // Issue command to extract the text String text = js.executeScript("return document.getElementById(' gsc-i-id1').value").toString(); System.out.println("Extracted text is" + text); driver.close(); } }
- Related Articles
- How do you enter text in the edit box in Selenium?
- How to press ENTER inside an edit box in Selenium?
- How to reset or clear an edit box in Selenium?
- How to enter a letter in uppercase in the edit box using Actions in Selenium?
- How to enter values in an edit box in Selenium with python?
- Get value of an input box using Selenium (Python)
- How to input letters in capital letters in an edit box in Selenium with python?
- How to get Value of a Edit Text field in Android using Kotlin?
- How to edit a JavaScript alert box title?
- How to get an attribute value of an element in Selenium Webdriver?
- How to get the value in a particular cell inside the worksheet in Selenium with python?
- How to get the attribute value of a web element in Selenium (using Java or Python)?
- How to input text in the text box without calling the sendKeys() using Selenium?
- How to get an attribute value from a href link in selenium?
- How to get all the options in the dropdown in Selenium?

Advertisements