say I have the HTML:
Based on solution from Miguel Rueda, but using prevSubject
option:
Cypress.Commands.add(
'selectNth',
{ prevSubject: 'element' },
(subject, pos) => {
cy.wrap(subject)
.children('option')
.eq(pos)
.then(e => {
cy.wrap(subject).select(e.val())
})
}
)
cy.get('[name=assignedTo]').selectNth(2)
children('option')
and .eq(pos)
traverse children of select to specific element.select
method with value of selected element.