Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress get element by aria role

<form>
    <input type='text' name='user'/>
</form>

Tying to get the input element via aria role 'textbox'. I've tried many different ways and everything comes back as 'not found'

cy.get('role=input')
cy.get('[role=input]')
cy.get('role="input")
cy.get('[role="input"])
cy.get('role=textbox')
cy.get('[role=textbox]')
cy.get('role="textbox")
cy.get('[role="textbox"])
cy.get('form[role="textbox"]')
cy.get('form[role=textbox]')

I've tried other things as well like capitalizing role. it's my understanding from the documentation that

cy.get('[role="textbox"]')

should work but returns not found.

You can see from dev-tools that it does have the role

enter image description here

like image 352
Jason G Avatar asked Aug 31 '25 03:08

Jason G


1 Answers

If a role is explicitly set, then you can assert like that: cy.get([role="${role}"], ...rest) If the role is implied by tag name, you can assert to the tag name as suggested by Rosen. If you want to assert a specific input, you can use e.g. the name like: cy.get('input[name="user"]')

like image 59
user19397277 Avatar answered Sep 02 '25 18:09

user19397277