Simulate slow typing in Protractor(在 Protractor 中模拟慢速打字)
问题描述
sendKeys()
方法会一次发送所有密钥(实际上,一次一个,但非常快):
sendKeys()
method would send all the keys at once (actually, one at a time but very quickly):
var elm = element(by.id("myinput"));
elm.sendKeys("test");
有没有办法减慢打字速度,以便 Protractor 一次发送一个字符,每个字符之间会有一点延迟?
Is there a way to slow the typing down so that Protractor would send one character at a time with a small delay between each of the characters?
我们可以完全减慢 Protractor,但这并不能改变 sendKeys()
的工作方式,它也会减慢一切,而我们只需要发送密钥"部分并且仅在特定情况下.
We can slow down Protractor entirely, but that does not change the way sendKeys()
works and it would also slow everything down while we just need the "send keys" part and only in specific cases.
推荐答案
思路是使用browser.actions()
并构造一系列发送密钥"命令——一个字符串中的每个字符.在每个发送密钥"命令之后,我们通过引入 自定义 sleep代码>动作.最后,这是我们提出的可重用函数:
The idea is to use browser.actions()
and construct a series of "send keys" command - one for every character in a string. After every "send keys" command we are adding a delay by introducing a custom sleep
action. At the end, here is a reusable function we've come up with:
function slowType(elm, keys, delay) {
var action = browser.actions().mouseMove(elm).click();
for (var i = 0; i < keys.length; i++) {
action = action.sendKeys(keys[i]).sleep(delay);
}
return action.perform();
}
用法:
slowType(elm, "some text", 100);
这篇关于在 Protractor 中模拟慢速打字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Protractor 中模拟慢速打字


基础教程推荐
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01