- 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 type in textbox using Selenium WebDriver with Java?
We can type in a textbox using Selenium webdriver. We shall use the sendKeys() method to type in the edit box. It is an in-built method in Selenium. Let us consider a text box where we shall enter some text.
First of all, we would identify the field with one of the locators and apply sendKeys() method on it.
Syntax −
driver.findElement(By.id("text-bx")).sendKeys("Tutorialspoint")
Example
Code Implementation.
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 InputTxt{ 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(5, TimeUnit.SECONDS); // identify element and input text inside it WebElement l =driver.findElement(By.className("gsc-input")); l.sendKeys("Selenium"); driver.quit(); } }
Output
- Related Articles
- How to scroll down using Selenium WebDriver with Java?
- How to get typed text from a textbox by using Selenium Webdriver?
- How to get selected option using Selenium WebDriver with Java?
- How to handle authentication popup with Selenium WebDriver using Java?
- Switch tabs using Selenium WebDriver with Java.
- How can I clear text of a textbox using Python Selenium WebDriver?
- How to scroll a specific DIV using Selenium WebDriver with Java?
- How to handle frame in Selenium WebDriver using java?
- How to use clickandwait in Selenium Webdriver using Java?
- How to select checkboxes using selenium java webdriver?
- How to send keyboard input to a textbox on a webpage using Python Selenium webdriver?
- Get page title with Selenium WebDriver using Java.
- Capturing browser logs with Selenium WebDriver using Java.
- How to deal with ModalDialog using selenium webdriver?
- How to perform mouseover function in Selenium WebDriver using Java?

Advertisements