How to specify ENTER button functionality in Selenium WebDriver code

0 votes
I'm figuring out a way to hit the "Enter" key in Selenium. Unfortunately the form I'm trying to test doesn't have a Submit button. Neither can I modify it since it is not my own code.

When working with it manually, I hit the "ENTER" button via keyboard. I need to know how to do that with the Selenium typecommand as there is no button to click.
Mar 23, 2018 in Selenium by Shubham
• 13,490 points
88,436 views

6 answers to this question.

0 votes

I'm assuming your writing the code in Java, so you can use the below code to find the element and then click on it:

driver.findElement(By.id("Value")).sendKeys(Keys.ENTER); 

or

driver.findElement(By.id("Value")).sendKeys(Keys.RETURN); 

For this to work, you should also import the "org.openqa.selenium.Keys" package.

answered Mar 23, 2018 by nsv999
• 5,500 points
+1 vote
using OpenQA.Selenium.Interactions;

Actions builder = new Actions(driver);        
builder.SendKeys(Keys.Enter);
For further understanding, you can refer to the Selenium Certification.
answered Feb 13, 2019 by anonymous
0 votes

using c#

IwebElement yourLastTextBox = driver.FindElement(By.<search Context>("element locator"));

YourLastTextBox.SendKeys(Keys.ENTER);
answered Mar 16, 2019 by Vivek Sharma
What would be the command if I'm using Python?

@Vardhan, you can use following lines of code in Python:

elem = driver.find_element_by_id("q")
elem.send_keys("dummy")
elem.send_keys(Keys.ENTER)
elem.send_keys(Keys.RETURN)
0 votes
WebElement webElement = driver.findElement(By.id("123"));/
webElement.sendKeys(Keys.TAB);
webElement.sendKeys(Keys.ENTER);
answered Sep 3, 2020 by Sri
• 3,190 points
0 votes

Selenium offers a '. click()' method to help you perform various mouse-based operations for your web-application. You can use the Selenium click button method for various purposes such as selecting the radio button and checkbox or simply clicking on any button or link, drag and drop, click and hold, etc.

answered Dec 11, 2020 by Roshni
• 10,520 points
0 votes

Press Enter/Return Key in Selenium

For pressing Enter key over a textbox we can pass Keys.ENTER or Keys.RETURN to the sendKeys method for that textbox.

WebElement textbox = driver.findElement(By.id("idOfElement"));
textbox.sendKeys(Keys.ENTER);

Or

WebElement textbox = driver.findElement(By.id("idOfElement"));
textbox.sendKeys(Keys.RETURN);
answered Dec 11, 2020 by Gitika
• 65,890 points

Related Questions In Selenium

0 votes
2 answers
0 votes
1 answer

How to automate radio button and checkbox on a webpage in Selenium Webdriver?

Hey Yashmita, following code snippet automates the ...READ MORE

answered Jul 23, 2019 in Selenium by Anvi
• 14,170 points
1,712 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
7,152 views
0 votes
2 answers

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

You first need to download chrome driver ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 28,120 points
1,354 views
+1 vote
1 answer

How to perform mouse hovering in Selenium WebDriver (Java)?

You many not actually be able to ...READ MORE

answered Apr 3, 2018 in Selenium by nsv999
• 5,500 points

edited Apr 4, 2018 by nsv999 9,296 views
0 votes
1 answer

How to use Actions class in Selenium Webdriver?

In seleniun webdriver it is not mandatory ...READ MORE

answered Apr 4, 2018 in Selenium by Damon Salvatore
• 5,980 points
3,492 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
9,504 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
7,642 views
0 votes
2 answers

What is the role of TestNG & JUnit frameworks in Selenium?

TestNG and JUnit are test frameworks . it ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
1,809 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
5,414 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP