0

I have a radio element <input type="radio" name="gender" value="male" />

below is my cypress code

cy.getAllByRole("radio").first().click()

how do I get the value attribute of the radio element? something like this

const radioValue = cy.getAllByRole("radio").first().getValue() //"male"

Rahul Yadav
  • 2,627
  • 5
  • 30
  • 52

1 Answers1

2

You can try this:

cy.getAllByRole('radio')
  .first()
  .invoke('val')
  .then((val) => {
    cy.log(val) //logs male
  })
Alapan Das
  • 17,144
  • 3
  • 29
  • 52