Search code examples
seleniumselenium-webdriverenterui-testing

What is the best practice to simulate an ENTER or RETURN using Selenium WebDriver


I came across this solution to my initial problem, which was to simulate an ENTER or RETURN key press using Selenium WebDriver.

However, in my code, I strictly want to use only one of the two WebElement.sendKeys(Keys.ENTER); vs WebElement.sendKeys(Keys.RETURN);.

What is the best practice when doing the same, since there seems to be divided opinion about using enter or return, since both work MOST of the time? In what scenarios would one or the other not work, and is there one which would ALWAYS work?


Solution

  • As a performancewise I do not get any change on both of these,

    But yes I know one difference on them

    Keys.Enter is used to enter key on the number pad

    while

    Keys.Return is used to one next to the letters

    Generally I have preferred Keys.Enteras sometimes in some browser Keys.Return is not worked for me