最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Typing with random delay cause some characters to not be typed - Stack Overflow

programmeradmin3浏览0评论

Using this function to type human like is partially working: the text is typed, but there's some random characters missing.

const slowType = async (elementHandle, message) => {
    const minDelay = 60;
    const maxDelay = 150;

    await elementHandle.focus();

    for (const chr of message) {
        console.log(chr);
        await elementHandle.type(chr);
        await sleep(Math.floor(Math.random() * (maxDelay - minDelay + 1)) + minDelay);
    }
};

// The use of the function:
message = 'lorem ipsum doloris';
const element = await page.$('textarea[id="xxx"]');
await slowType(element, messages);

all characters are printed from the console.log(), but some are missing in the final textarea. There's no errors. Tried many things like page.type('selector', chr).

How can I fix this?

发布评论

评论列表(0)

  1. 暂无评论