How can I reduce TypeText delay in Watin?

How to reduce the delay between keystrokes in the TypeText Watin method? Is there a better way if I want to "instantly" type text?

+6
c # watin
source share
4 answers

Answer the .ClickNoWait() on the element, and then just set its .Value property.

Hope this helps someone.

+6
source share

I know him a little late, but I could also share this some information for others having the same problem that are landing here, especially considering that you asked for an example.

 IE browser = new IE(); browser.TextField("UserName").Value = "admin"; browser.TextField("Password").Value = "pass123"; 

Enjoy. Here is a good post on an alternate path where I found this some time ago.

+7
source share
  LoginPage LoginPage = Browser.Page<LoginPage>(); string UserName = ConstVars.UserName; string Password = ConstVars.Password; if (LoginPage.UserNameTextField.GetAttributeValue("value") != UserName) { LoginPage.UserNameTextField.SetAttributeValue("value", UserName); } if (LoginPage.PasswordTextField.GetAttributeValue("value") == null) { LoginPage.PasswordTextField.SetAttributeValue("value", Password); } LoginPage.ClickLoginButton(); 

For me, just setting the value attribute for the text field being processed, but this may depend on how the page is encoded.

+2
source share

I ran into this problem, and just clicking on the text field and setting the value caused testing errors, because our ASP.NET WebForms application has validators that are executed when the change event is triggered. Here is the source code for the extension for WatiN:

 using WatiN.Core; namespace Project.Extensions { public static class WatinExtensions { public static void TypeTextFaster(this TextField textfield, string value) { textfield.Value = value; textfield.Change(); } } } 

If you have event handlers that fire when the user clicks on textfield , just add textfield.Click() or textfield.ClickNoWait() before setting the value.

Remember the line using Project.Extensions; at the beginning of your code to enable the WatiN extensions.

Now you can call the extension method:

 TextField field = browser.TextField("id"); field.TypeTextFaster("the text to type"); 
0
source share

All Articles