2
votes

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.

1
Do you want to select the nth child of an element ? If so, see here. Otherwise please edit your question with more details on what you want to do, and what you have tried.Arnaud P

1 Answers

2
votes

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