如何减少 Watin 中的 TypeText 延迟?

发布于 2024-10-09 13:59:21 字数 63 浏览 0 评论 0原文

如何减少 Watin 的 TypeText 方法中按键之间的延迟?如果我想“即时”输入一些文本,有更好的方法吗?

How does one reduce the delay between keypresses in the TypeText method of Watin? Is there a better way if I want to "instantaneously" type some text?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

执笔绘流年 2024-10-16 13:59:21

我知道有点晚了,但我不妨为其他有同样问题的人分享这些信息,特别是考虑到你要求提供一个例子。

IE browser = new IE();

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

玩得开心。 这里是一篇关于另一种方法是我前段时间发现的。

I know its a bit late but I might as well share this bit of info for others having the same problem who land here especially considering you asked for an example.

IE browser = new IE();

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

Have fun. Here is a nice post on an alternative way which is where I found this some time back.

在你怀里撒娇 2024-10-16 13:59:21

答案是在元素上使用 .ClickNoWait(),然后设置其 .Value 属性。

希望这对某人有帮助。

The answer is to .ClickNoWait() on the element, and then just set its .Value property.

Hope this helps someone.

浪菊怪哟 2024-10-16 13:59:21
    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();

对我来说,只需设置文本字段的值属性就可以了,但这可能取决于页面的编码方式。

    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, simply setting the value attribute for the text field worked, but it could depend on how the page is coded.

人间不值得 2024-10-16 13:59:21

我也遇到了这个问题,仅仅单击文本字段并设置值就会导致测试失败,因为我们的 ASP.NET WebForms 应用程序具有在 change 事件触发时执行的验证器。以下是 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();
        }
    }
}

如果您有在用户单击 textfield 时触发的事件处理程序,只需添加 textfield.Click() 或 < code>textfield.ClickNoWait() 在设置值之前。

请记住代码开头的 using Project.Extensions; 行以包含 WatiN 扩展。

现在您可以调用扩展方法:

TextField field = browser.TextField("id");

field.TypeTextFaster("the text to type");

I ran into this problem as well, and just clicking on the text field and setting the value was causing test failures because our ASP.NET WebForms application has validators that execute when the change event fires. Here is the source code for an Extension to 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 get triggered when the user clicks on the textfield, just add textfield.Click() or textfield.ClickNoWait() before setting the value.

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

Now you can call the extension method:

TextField field = browser.TextField("id");

field.TypeTextFaster("the text to type");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文