- 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 simulate pressing enter in html text input with Selenium?
We can simulate pressing enter in the html text input box with Selenium webdriver. We shall take the help of sendKeys method and pass Keys.ENTER as an argument to the method. Besides, we can pass Keys.RETURN as an argument to the method to perform the same task.
Also, we have to import org.openqa.selenium.Keys package to the code for using the Keys class. Let us press ENTER/RETURN after entering some text inside the below input box.
Example
Code Implementation with Keys.ENTER.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; import org.openqa.selenium.Keys; public class PressEnter{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/about/about_careers.htm"); // identify element WebElement l=driver.findElement(By.id("gsc-i-id1")); l.sendKeys("Selenium"); // press enter with sendKeys method and pass Keys.ENTER l.sendKeys(Keys.ENTER); driver.close(); } }
Code Implementation with Keys.RETURN.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; import org.openqa.selenium.Keys; public class PressReturn{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/about/about_careers.htm"); // identify element WebElement l=driver.findElement(By.id("gsc-i-id1")); l.sendKeys("Selenium"); // press enter with sendKeys method and pass Keys.RETURN l.sendKeys(Keys.RETURN); driver.close(); } }
- Related Articles
- How to fire after pressing ENTER in text input with HTML?
- How to detect pressing Enter on keyboard using jQuery?
- Detect the ENTER key in a text input field with JavaScript
- How do you enter text in the edit box in Selenium?
- JavaScript Submit textbox on pressing ENTER?
- How to key in values in input text box with Javascript executor in Selenium with python?
- How to input text in the text box without calling the sendKeys() using Selenium?
- How to Create a Multi-line Text Input (Text Area) In HTML?
- How to enter values in an edit box in Selenium with python?
- How to simulate HTML5 Drag and Drop in Selenium Webdriver?
- HTML DOM Input Text object
- How can I consistently remove the default text from an input element with Selenium?
- How to simulate Print screen button using selenium webdriver in Java?
- HTML DOM Input Text size Property
- HTML DOM Input Text type Property

Advertisements