Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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");

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
493 views
Welcome To Ask or Share your Answers For Others

1 Answer

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();
}

Usage:

slowType(elm, "some text", 100);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...