1

enter image description here

How to write locator for this highlighted input field element when ID and Class attribute are dynamic?

Also for this button

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
Rock
  • 115
  • 7

1 Answers1

1

The "Course name" text is a notable feature of that block of HTML. Select it and use traversal commands to get to the <input>

cy.contains('span', 'Course name')
  .next()
  .find('input')

Alternatively, the placeholder text could be used (but it seems a bit generic)

cy.get('input[placeholder="Enter"]')

For the <button> a similar tactic

cy.contains('p', 'Add new course')
  .prev('button')
  .click()
Fody
  • 23,754
  • 3
  • 20
  • 37