How to press enter using selenium in Java

+2 votes
I am trying to search a keyword in Google and instead of clicking on the search button I just want to click enter. How can I do this in Selenium?

I am using Eclipse(Java).

Thank you in advance.
Dec 21, 2018 in Selenium by Jino
• 5,820 points
4,583 views

1 answer to this question.

+2 votes

Hey @jino, good that you are finding alternatives to do a task. Talking about pressing enter, enter is a keystroke and is considered as same in selenium aswell. 

When you enter any keyword, you use .sendKeys("Your keyword");

For pressing enter also you do the similar thing but instead of writing enter you make enter a keystroke.

The step being this:

driver.findElement(By.id("id of your text bar")).sendKeys("Your keyword",Keys.ENTER);

Hope this was of some help.

To know more about Java, It's recommended to join our Java Training in Chennai today.

answered Dec 21, 2018 by Priyaj
• 58,020 points

edited Oct 7, 2021 by Sarfaraz

Related Questions In Selenium

+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
8,430 views
0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
19,004 views
0 votes
1 answer

How to handle Pop-up in Selenium WebDriver using Java

Actually, its pretty simple. Use this code ...READ MORE

answered Apr 6, 2018 in Selenium by nsv999
• 5,500 points
10,628 views
+11 votes
17 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,360 points
198,460 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
13,805 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
9,209 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,910 points
7,287 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,914 views
0 votes
2 answers

How to handle dropdowns in selenium?

Hey @Rishab, you can take a look ...READ MORE

answered Jan 23, 2019 in Selenium by Priyaj
• 58,020 points
1,062 views
0 votes
1 answer

How to refresh in selenium webdriver?

There are multiple methods using which you ...READ MORE

answered Feb 13, 2019 in Selenium by Priyaj
• 58,020 points
3,538 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