我在之前的版本中遇到过这个问题,并提交了一个错误报告。它已经被修复了,但也许它又被打破了?在任何情况下,当我们在protractor chat channel上讨论这个时,都提出了以下建议:正常使用sendKeys,然后验证结果。如果结果未通过健全性检查,则一次输入一个字符。
/**
* A Typescript version that can be used as a mixin.
* Make some minor modifications to use as a class.
* @param data {string} The string to enter in the input element
*/
export class SendKeys {
inputEl: ElementFinder;
sendKeys(data: string) {
var el = this.inputEl;
// click on the input before sending data. This helps the focus and action situations.
el.click();
el.clear();
el.sendKeys(data);
// Verify whether or not hte whole data value was sent.
// If not, send data one character at a time, which works.
// See: https://github.com/angular/protractor/issues/3196
el.getAttribute('value').then(function (insertedValue) {
if (insertedValue !== data) {
// Failed, must send characters one at a time
el.clear();
for (let i=0; i < data.lenght; i++) {
el.sendKeys(data.charAt(i));
}
}
});
}
}
-
/**
* The Javascript version:
* @param el {ElementFinder} The input element reference
* @param data {string} The string to enter in the input element
*/
export function sendKeys(el, data) {
var el = this.inputEl;
// click on the input before sending data. This helps the focus and action situations.
el.click();
el.clear();
el.sendKeys(data);
// Verify whether or not hte whole data value was sent.
// If not, send data one character at a time, which works.
// See: https://github.com/angular/protractor/issues/3196
el.getAttribute('value').then(function (insertedValue) {
if (insertedValue !== data) {
// Failed, must send characters one at a time
el.clear();
for (let i=0; i < data.lenght; i++) {
el.sendKeys(data.charAt(i));
}
}
});
}
我试着用executeScript,但发生同样的问题。 – RFtests