如何使用TestCafe确定元素属性是否存在?

Prr*_*Prr 3 automated-tests css-selectors e2e-testing testcafe

我正在使用TestCafe,并想确定checkbox元素是否存在。在HTML元素中,如果该复选框已被选中,则该属性checked存在,否则不存在。如何确定使用TestCafe?

我使用了TestCafe中可用的功能- .hasAttribute('checked')但返回的是undefined

选中此复选框时,以下是HTML代码:

<input class="jss1523" tabindex="-1" type="checkbox" data-indeterminate="false" value checked>

取消选中此复选框时,这是HTML代码:

<input class="jss1523" tabindex="-1" type="checkbox" data-indeterminate="false" value>

如何使用TestCafe解决此问题?

小智 5

对于那些你让每一个DOM元素Selector(),你可以检查属性checked- https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/dom-node-state.html#members-specific-to -元素节点

对于复选框和单选输入,它返回布尔值(true-如果选中,则为-false otherwise),而对于其他类型的元素则返回undefined