How to target a checkbox that has no id, name and class attribute?

Viewed 158

I am trying to target a checkbox using cypress that has no id and classname and assert it is checked on click. I have tried a couple of ways including this and it does not work.

cy.get('[type=checkbox]').select('Store')

The code looks like this

<h2>
  <input type="checkbox" 
         tri-state="" 
         ng-model="data.root" 
         class="ng-valid ng-touched ng-dirty ng-valid-parse">Store 
</h2>
1 Answers

.select() is for dropdowns (well some of them), but .check() is for checkboxes docs

cy.contains('h2', 'Store')
  .find('[type=checkbox]')
  .check()

There's something a little bit off with the html, the <input> isn't closed. Probably does not matter, but to be safe id the <h2> with the "Store" text, then .find() takes you inside the <h2>.

Related