Reputation: 365
Is there a way in Cypress.io to select a specific child of a element as opposed to using the containing text or value? In my case, the data changes and thus the test will break if used with a different set of data that is not hard-coded in.
Upvotes: 2
Views: 3223
Reputation: 18053
Here's how you'd use select()
based on index. First you get the 4th
value of the select
, then use a .then()
that yields it's value
:
cy.get('select.myselect option').eq(4).invoke('val').then((val)=>{
cy.get('select.myselect').select(val)
})
// .eq(n) yields the nth element
Upvotes: 2