如果代码段中没有 "disabled",如何检查量角器是否禁用 mat-select?

How to check in protractor is mat-select disable, if there is no "disabled" in snippet?

我使用页面对象中的表格并希望避免 getAttribute(mat-select-disabled),只是 isEnabled(),因为输入和复选框等其他元素具有 "disabled"

<mat-select class="mat-select mat-select-disabled formcontrolname="xxx" role="listbox" aria-disabled="true"></mat-select>

没有为此构建的方法,您无法避免使用 getAttribute 方法,因为您的元素没有 disabled 属性,只有一个 class 名称。

但您始终可以创建自己的,如下所示:

// async/await

async function isElementDisabled(elem) { @elem <ElementFinder>
  const classNames = await elem.getAttribute('class');

  return classNames.includes('mat-select-disabled');
}

// Promise based

function isElementDisabled(elem) { // @elem <ElementFinder>
  return elem.getAttribute('class').then(classNames => classNames.includes('mat-select-disabled'));
}