5

I have a button on my website with two classes:

<button class="btn_primary btn_inventory">ADD TO CART</button>

I want to click this button with this code:

 cy.get('btn_primary btn_inventory').click();
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • 4
    Remove the space and replace it with a `.` like `'btn_primary.btn_inventory'` Dont know `Cypress` but you might also need a `.` at the start `'.btn_primary.btn_inventory'` – Carsten Løvbo Andersen Jul 15 '20 at 11:12

1 Answers1

11

You can't directly use the class name as you have used here. you need to use CSS selectors. in your case, it should be corrected as,

cy.get('.btn_primary.btn_inventory').click();

Refer this to learn more about css selectors CSS Selectors W3Schools

Muditha Perera
  • 1,216
  • 8
  • 24