2

我正在使用带有 Jasmine 的 FuncUnit 来测试我的 Web 应用程序,我遇到的一个问题始终与输入类型编号有关。

<input type="number" min="0.01" step="0.01" pattern="[0-9]+([\.|,][0-9]+)?" class="form-control m-wrap m-ctrl-large" placeholder="10" onkeypress=" return isDecimalKey(event); ">

isDecimalKey方法主要检查类型代码以确保用户输入的是数字或小数点:

function isDecimalKey(e) {
    var charCode = (e.which) ? e.which : event.keyCode;
    if (charCode !== 46 && charCode > 31
        && (charCode < 48 || charCode > 57))
        return false;
    else
        return true;
}

手动输入输入时,我可以使用 Ctrl+A 突出显示当前值,使用退格键或删除键将其删除,然后输入新值。但是,当尝试对 FuncUnit 执行相同操作时,出现以下错误:

Uncaught InvalidStateError: Failed to read the 'selectionStart' property from 'HTMLInputElement': The input element's type ('number') does not support selection.

我尝试了以下插入方法:

F('input').visible().click().type('[ctrl]a[ctrl-up][delete] 6');
F('input').visible().click().type('[\b][\b] 6');
F('input').visible().click().type('6');
F('input').visible().dblclick().type('6');

到目前为止,以上都没有奏效。对我来说,操纵这个输入值的最佳方法是什么?谢谢!

4

0 回答 0