檢查元素的指定屬性是否存在,並可選擇是否具有預期的值。

用法

                    browser.expect.element(selector).to.have.attribute(attribute)
                

範例

this.demoTest = function (browser) {
  browser.expect.element('body').to.have.attribute('data-attr');
  browser.expect.element('body').to.not.have.attribute('data-attr');
  browser.expect.element('body').to.not.have.attribute('data-attr', 'Testing if body does not have data-attr');
  browser.expect.element('body').to.have.attribute('data-attr').before(100);
  browser.expect.element('body').to.have.attribute('data-attr')
    .equals('some attribute');
  browser.expect.element('body').to.have.attribute('data-attr')
    .not.equals('other attribute');
  browser.expect.element('body').to.have.attribute('data-attr')
    .which.contains('something');
  browser.expect.element('body').to.have.attribute('data-attr')
    .which.matches(/^something\ else/);
};

參數

名稱 類型 描述
attribute 字串

屬性名稱

message
可選
字串

顯示在輸出中的可選日誌訊息。如果缺少,則預設會顯示一個訊息。