As far as I'm aware there are two ways of typing with Selenium:
new Actions(webDriver).sendKeys("text to send").perform();
webElement.sendKeys("text to send");
The Actions
method seems like the most natural way of replicating a user typing as the keys are sent wherever the browser wants (I believe a method called sendKeysToActiveElement is being used under the covers). However, many tutorials instruct testers to use the WebElement
method (this is in fact the only option when using SafariDriver), I assume as it is simpler.
Is the Actions
method actually a better simulation of user interaction, or should I use the WebElement
method for convenience?
public Actions sendKeys(java.lang.CharSequence... keys)
Sends keys to the active element. This differs from calling WebElement.sendKeys(CharSequence...) on the active element in two ways:
for more you can refer this link : https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html#sendKeys-java.lang.CharSequence...-