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,380 points
27,973 views

3 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,510 points
+1 vote
using OpenQA.Selenium.Interactions;

Actions builder = new Actions(driver);        
builder.SendKeys(Keys.Enter);
answered Feb 12, 2019 by anonymous
0 votes

using c#

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

YourLastTextBox.SendKeys(Keys.ENTER);
answered Mar 15, 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)

Related Questions In Selenium

0 votes
1 answer
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 22, 2019 in Selenium by Anvi
• 14,030 points
661 views
0 votes
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,510 points
3,438 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
• 27,920 points
547 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,510 points

edited Apr 4, 2018 by nsv999 5,059 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,540 points
2,728 views
0 votes
1 answer

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,510 points
2,547 views
0 votes
1 answer
0 votes
1 answer

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

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

answered Apr 18, 2018 in Selenium by king_kenny
• 3,710 points
635 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,870 points
2,026 views