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');
Or to get the text of the option, use text() : $var = jQuery("#dropdownid option:selected").
cypress will not allow a click of an option, because it think options are invisible because the parent is invisible. The work around is to use . then() to get access to the unwrapped list item, and use jquery click to select it instead of cypress click.
You can use the jQuery :selected selector in combination with the val() method to find the selected option value in a select box or dropdown list.
This worked for me:
cy.get('#id-9999').find('.categoryList').find(':selected').contains('Miscellaenous')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With