Press Enter Key in Selenium

If you are working with a SearchBox using Selenium. In which you have to type something and you have to press Enter to search. You can do it in the following way...

// this sends an Enter to the element

selenium.type("locator", Keys.ENTER);

// The below code sends the "Any text" and then confirms it with Enter

selenium.type("locator", "Any text" + Keys.ENTER);

Here locator means You have to add the TextBox's Id.  

or try this



selenium.keyDown("locator of element", "\\13");

Where 13 is the ASCII value of Enter Key.. 

Hope this may help you.

No comments:

Post a Comment