您的位置:首页 > 编程语言 > ASP

WatiN TextField and ASP.NET AJAX MaskedEdit Controls

2009-09-22 23:10 423 查看
If you have tried to user WatiN tests to set the value of text boxes/fields, you likely have run into a few things.

First, this...
ie.TextField("ID").Value = "some text";
is much faster than this...
ie.TextField("ID").TypeText("some text");

Next, if you are using client side validation or any of the MaxkedEdit controls, you probably discovered that it does not play too well. I originally used this just to make it work for me...

TextField textField = ie.TextField(Find.ById(new Regex(controlId)));

textField.Focus();
for (int i = 0; i < value.Length; i++)
{
textField.KeyPress(char.Parse(value.Substring(i, 1)));
textField.WaitForComplete();
}

For one, it is pretty slow. Also, it just does not seem to work 100% of the time. WatiN exposes one additional method to make this a lot faster. Eval() will allow you to inject and run javascript in the instance of the browser..

TextField textField = ie.TextField(Find.ById(new Regex(controlId)));
string eval = string.Format("document.getElementById('{0}').value = '{1}'", textField.Id, value);
ie.Eval(eval);

Happy Testing!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐