Home > Software engineering >  how to get value attribute of radio input with cypress?
how to get value attribute of radio input with cypress?

Time:01-24

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"

CodePudding user response:

You can try this:

cy.getAllByRole('radio')
  .first()
  .invoke('val')
  .then((val) => {
    cy.log(val) //logs male
  })
  • Related