cypress

Cypress: How do I get the text of the selected option in a select drop-down list?


I want to be able to get the text of the selected option and not the value. I would use the value but Angular is changing it and putting the value in a ng-reflect-ng-value attribute.

<option _ngcontent-c1="" value="5: 1" ng-reflect-ng-value="1">Miscellaenous</option>

This will work, but I want to check that it equals "Miscellaenous"

cy.get('#id-9999').find('.categoryList').should('have.value','Miscellaenous');

Solution

  • This worked for me:

    cy.get('#id-9999').find('.categoryList').find(':selected').contains('Miscellaenous')