Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if element attribute exists or not using TestCafe?

I'm using TestCafe and would like to determine if the checkbox element is present or not. In the HTML element, if the checkbox is already checked then the attribute checked exists otherwise not. How do I determine using TestCafe?

I used the function available in TestCafe - .hasAttribute('checked') but the return is undefined.

Here is the HTML code when the checkbox is checked:

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

Here is the HTML code when the checkbox is unchecked:

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

How do I solve this using TestCafe?

like image 633
Psdet Avatar asked Nov 19 '25 23:11

Psdet


1 Answers

For every Dom element which you get with Selector() you can check property checked - https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/dom-node-state.html#members-specific-to-element-nodes

For checkboxes and radio inputs it returns Boolean value (true - if checked, otherwise - false) and for other types of elements return undefined

like image 115
RedVarVar Avatar answered Nov 22 '25 17:11

RedVarVar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!