仅在启用按钮时输入

问题描述 投票:0回答:1

我正在尝试检查按钮是否已启用,然后输入值并提交。我用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');
} 
protractor
1个回答
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(.....)
© www.soinside.com 2019 - 2024. All rights reserved.