Watir .set vs .send_keys

Selenium allows for two ways of entering text into text fields: character by character (as if typing) or all characters at once (imitating CTRL+V).

The following snippet of Ruby code shows how it’s done in Ruby using the Watir wrapper framework for Selenium.

@browser = Watir::Browser.new :firefox

@browser.goto "http://demo.redmine.org/"

@browser.text_field(id: "username").send_keys "my_login" #typing
@browser.text_field(id: "password").put "my_login" #pasting

In Java, the same could be accomplished using the fastSetValue switch in Selenide. (However in Selenide there is only one method for putting text into text fields, the .setValue() method.)

Configuration.browser = "firefox";

Configuration.fastSetValue = false;
$("#username").setValue("my_login"); // typing

Configuration.fastSetValue = true;
$("#username").setValue("my_login"); // pasting

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s