可点击但不可见?

时间:2017-08-24 22:45:20

标签: protractor

我对Protractor E2E测试还不熟悉,并且想知道元素是否可以点击(ExpectedConditions.elementToBeClickable)但不一定是可见的(ExpectedConditions.visibilityOf)。

例如,我有以下代码:

    var EC = protractor.ExpectedConditions;
    var tryItButtonClickable = EC.elementToBeClickable(tryItButton);
    var tryItButtonVisible = EC.visibilityOf(tryItButton);

    return browser.wait(EC.and(tryItButtonClickable, tryItButtonVisible), getWaitTime())
        .then(function() {
             var protocol = url.parse(myarray[0].url).protocol;
                 if (protocol === null) {
                     throw new Error('expected ' + protocol + ' not to be null');
                 }
        })

在添加tryItButtonVisible之前,我会收到Protractor的超时错误,大概是因为我的tryItButton是可点击的,但还没有被加载到DOM中。

这是真的,还是我是多余的?

由于

1 个答案:

答案 0 :(得分:0)

这是量角器的正常可点击功能

elementToBeClickable(elementFinder: ElementFinder): Function {
return this.and(this.visibilityOf(elementFinder), () => {
  return elementFinder.isEnabled().then(passBoolean, falseIfMissing);
})

如您所见,它首先检查元素可见性,因此答案为否

资源:https://github.com/angular/protractor/blob/master/lib/expectedConditions.ts行:188