首页 > 解决方案 > TestCafe - Windows 10 上的 Internet Explorer 11 输入文本问题

问题描述

我的 testcafe 测试使用 Internet Explorer 将文本输入到文本字段中,但是当它输入文本时,它会删除所有其他字母。

例如:test@something.com将输入为ts@oehn.cm

await t.typeText(Selector('#email'), 'myemail@email.com')

await t.typeText(Selector('#password'), 'mypassword')

await t.click(Selector('.account-form__button'))

await t.wait(6000);

这是有人见过的吗?相同的测试在 Windows 上的 Firefox 和 chrome 中运行良好。

标签: javascriptwindows-10internet-explorer-11e2e-testingtestcafe

解决方案


此问题可能与键入速度和附加到输入字段的事件处理程序有关:这些事件处理程序的执行速度比输入 keyup/keydown 频率慢。解决方法是像真实用户一样输入文本(即逐个字母):

const selector = Selector('#email');
const letters = [...'myemail@email.com'];
let index = -1;
for (const letter of letters) {
    index += 1;
    if (index === 0) {
        await t.typeText(selector, letter, {replace: true});
        continue;
    }
    await t
        .wait(100)
        .typeText(selector, letter);
}

推荐阅读