如何使用 TestCafe 确定元素属性是否存在?
How to determine if element attribute exists or not using TestCafe?
我正在使用 TestCafe 并想确定复选框元素是否存在。在 HTML 元素中,如果复选框已被选中,则属性 checked
存在,否则不存在。我如何确定使用 TestCafe?
我使用了 TestCafe 中可用的函数 - .hasAttribute('checked')
但 return 是 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 解决这个问题?
对于使用 Selector()
获得的每个 Dom 元素,您可以检查 属性 checked
- https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/dom-node-state.html#members-specific-to-element-nodes
对于复选框和单选输入,它是 returns 布尔值(true
- 如果选中,otherwise
- 假),对于其他类型的元素 return undefined
我正在使用 TestCafe 并想确定复选框元素是否存在。在 HTML 元素中,如果复选框已被选中,则属性 checked
存在,否则不存在。我如何确定使用 TestCafe?
我使用了 TestCafe 中可用的函数 - .hasAttribute('checked')
但 return 是 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 解决这个问题?
对于使用 Selector()
获得的每个 Dom 元素,您可以检查 属性 checked
- https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/dom-node-state.html#members-specific-to-element-nodes
对于复选框和单选输入,它是 returns 布尔值(true
- 如果选中,otherwise
- 假),对于其他类型的元素 return undefined