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.KeyPressNative("13");

or


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

Where 13 is the ASCII value of Enter Key.. 

Hope this may help you.

1 comment:

  1. Your information about Selenium scripts is really interesting. Also I want to know the latest new techniques which are implemented in selenium. Can you please update it in your website?
    Regards,
    Selenium Training in Chennai|Selenium Course in Chennai

    ReplyDelete