3
<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

Jason G
  • 2,395
  • 2
  • 24
  • 34

2 Answers2

2

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"]')

0

You can use this css selector

cy.get('input[type="text"]')

Omama Zainab
  • 741
  • 4
  • 14
  • 24
Rosen Mihaylov
  • 1,363
  • 2
  • 10
  • 2
    yes this will get the inputs, i ended up installing @testing-library/cypress and using it's roles, but it also doesn't always work. so i'm using a combination of cy.contains('role', 'text/title') and cy.findByRole('role', {name: }) – Jason G Nov 02 '20 at 17:48