WatiN TextField and ASP.NET AJAX MaskedEdit Controls

3 篇文章 0 订阅

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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值