Pass a key stroke (i.e., Enter Key) into application using WatiN scripts

vinaykumar picture vinaykumar · May 13, 2009 · Viewed 18.5k times · Source

I'm using WatiN testing tool. Can I pass a key stroke (i.e., pressing a enter key) to the application using WatiN scripts?

This option was available in WatiR. Is this option available in WatiN?

Answer

Jose Basilio picture Jose Basilio · May 13, 2009

EDIT: Upon further inspection, I found that the standard way of sending the ENTER key doesn't work in WatiN as it does in WatiR. You need to use System.Windows.Forms.SendKeys

Also, I recommend that you download the WatiN Test Recorder.

Here's the sample code.

using(IE ie = new IE("http://someurl"))
{
  TextField myTxt = ie.TextField(Find.ById("myTextBox")).TypeText("some value");
  System.Windows.Forms.SendKeys.SendWait("{ENTER}");      
}