仅在启用按钮时输入

时间:2018-03-06 12:41:55

标签: protractor

我正在尝试检查按钮是否已启用,然后输入值并提交。 我用if else循环来检查这个。但执行永远不会进入循环。以下是使用的代码。

await this.sendButton.isEnabled().then(async function(enabled) {
    if(enabled) {
        await $('.input').sendKeys('abc');
await $('.send-btn').click();
await  $$('.value' ).getText().then(async function(itemList) {
await expect(itemList).toContain('abc');
});enter code here
}
else {
console.log('button is disabled');
} 

1 个答案:

答案 0 :(得分:0)

启用没有if语句的运行?

await this.sendButton.isEnabled().then(async function (enabled) {
    await $('.input').sendKeys('abc');
    await $('.send-btn').click();
    await $$('.value').getText().then(async function (itemList) {
        await expect(itemList).toContain('abc');
    });

}

你检查按钮是启用还是禁用 - isEnabled - 所以乍一看,if语句是不必要的,你可以写另一个期望,即禁用状态。

.isEnabled().toBe(false).then(.....)