Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to press 'Enter' once text is entered in the search field using Selenium WebDriver and java code in eclipse

I am trying to write test case using WebDriver, TestNG in Eclipse. Version of WebDriver is 2.39

In the test case I am trying to open a browser, enter site address, once it is loaded, find search field, enter text using Datadriven type from an excel sheet.

Once the first data is entered, I would like to click Return key on keyboard and wait till loads and clear it and enter next test from spreadsheet.

I am successfull in entering text,clearing, but not sure how to write code to press 'Return key' or Enter, please advise.

Apologies, I could not find this in search.

regards,

like image 504
user2691854 Avatar asked Dec 05 '22 07:12

user2691854


1 Answers

You can simulate hit Enter key by adding "\n" to the entered text. For example textField.sendKeys("text you type into field" + "\n").

upd: BTW, it has been already asked here Typing Enter/Return key in Selenium

like image 91
olyv Avatar answered Dec 22 '22 01:12

olyv