我在之前的版本中遇到過這個問題,並提交了一個錯誤報告。它已經被修復了,但也許它又被打破了?在任何情況下,當我們在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