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,300 points
10,234 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,090 points
+1 vote
using OpenQA.Selenium.Interactions;

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

using c#

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

YourLastTextBox.SendKeys(Keys.ENTER);
answered Mar 15 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 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,090 points
2,173 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 in Selenium by Abha
• 25,240 points
286 views
0 votes
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,090 points

edited Apr 4, 2018 by nsv999 3,130 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,510 points
2,481 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,090 points
780 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,650 points
303 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,130 points
1,024 views