【问题标题】:Clicking if element is clickable in protractor如果元素在量角器中可单击,则单击
【发布时间】:2018-01-04 08:20:12
【问题描述】:

在网站上,我有时会在表单中添加用于恢复自动保存数据的附加按钮,该按钮会随机弹出(有时有人测试某些内容并关闭表单,这会导致弹出按钮)。我尝试使用Continue if element is not visible in protractor 使用以下代码:

let DoNotRefillBtn=element.all(by.className('modal-button-no'));
    var isApproachable = function(element) {
        return element.isPresent().then(function (present) {
            return present
                ? element.isDisplayed()
                : false;
        });
    };

describe(...)
    it('Open the form:', function () {
            browser.driver.get('foo');
            browser.sleep(1000);
            isApproachable(DoNotRefillBtn).then(function(approachable) {
                if (approachable) {
                    DoNotRefillBtn.click();
                    browser.sleep(500);
                }
                else {
                    browser.sleep(300);
                }
            });

点击正确,但点击后,在DoNotRefillBtn.click();行抛出错误Failed: element not visible

为什么程序点击并抛出一个东西不可点击的错误(点击后)?

【问题讨论】:

  • 我不确定,但return present ? element.isDisplayed() : false; 看起来很臭。它返回<Promise>boolean
  • 我有这个问题:stackoverflow.com/questions/36201154/… 并返回布尔值

标签: jasmine protractor


【解决方案1】:

我使用了一种解决方法,该按钮带有状态消息“您要重新填写表格吗?”。因此,当我检查状态消息并单击按钮时,似乎正在工作:

let StatusMessage=element.all(by.className('status-message'));
let DoNotRefillBtn=element.all(by.className('modal-button-no'));
var isApproachable = function(element) {
   return element.isPresent().then(function (present) {
      return present
        ? element.isDisplayed()
          : false;
    });
};

describe(...)
it('Open the form:', function () {
        browser.driver.get('foo');
        browser.sleep(1000);
        isApproachable(StatusMessage.get(8)).then(function(approachable) {
                if (approachable) {
                    DoNotRefillBtn.get(0).click();
                    browser.sleep(500);
                }
            });
    });
});

StatusMessage.get(8) 是 8,因为还有更多具有相同类的消息,但未显示。我数了一下是哪个status-message,它似乎正在工作 - 如果显示则关闭弹出窗口,但不显示时会跳过。

适当地检查按钮并单击它会产生一些问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    相关资源
    最近更新 更多