发送多个按键 WatiN
好的,我正在 WatiN 中运行测试,并且使用 SendKeys 方法。根据MSDN网站我可以输入:
System.Windows.Forms.SendKeys.SendWait("{LEFT 2}");
并且这会向左输入两次。然而,我相信这不起作用,因为应用程序在每次按键之间需要时间。我为了做我需要程序做的事情,我在每次按键之间使用 Thread.Sleep 以确保它们被读取。 有更有效/正确的方法吗?这是我当前的方法代码:
System.Windows.Forms.SendKeys.SendWait("{LEFT}");
Thread.Sleep(500);
System.Windows.Forms.SendKeys.SendWait("{LEFT}");
Thread.Sleep(500);
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
Ok so I am running tests in WatiN and I am using the SendKeys method. According to the MSDN website I can enter:
System.Windows.Forms.SendKeys.SendWait("{LEFT 2}");
And this will enter left two times. This however does not work, I believe because the application needs time between each keypress. I order to do what I need the program to do I used Thread.Sleep between each keypress to ensure they were getting read. Is there a more efficient/proper way to do this? This is my current method code:
System.Windows.Forms.SendKeys.SendWait("{LEFT}");
Thread.Sleep(500);
System.Windows.Forms.SendKeys.SendWait("{LEFT}");
Thread.Sleep(500);
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,我不相信有。根据 MSDN 存在计时问题使用发送键:
您可以尝试更改实现以查看结果是否有变化。
或者,根据此帖子,仅使用
Thread。 Sleep(0);
在您的输入应该起作用之后。这不是最优雅的解决方案,但如果它有效,它将比 500 毫秒的暂停更快。Unfortunately, I don't believe there is. According to MSDN there are timing issues with SendKeys:
You could try changing between implementations to see if there is a change in your results.
Alternately, according to this post just using
Thread.Sleep(0);
after your input should work. Not the most elegant solution but if it works it would be faster than a 500ms pause.