From the list of values, how to select each dropdown value after some action is done using cypress?

27 Views Asked by At

dev code

cy.get('#gradeLevels').each(($option) => {
    const optionText = $option.text();
    cy.get('#gradeLevels').select('Grade 3');
    cy.log('List of Grade Levels'+ optionText) })

I'm trying the above code, but unable to capture the list. Also, want to know how to capture or log the dropdown list values. Thanks in advance.

1

There are 1 best solutions below

0
Shafi S On
cy.get("#gradeLevels").find("option").each(($option) => {
    cy.get("#gradeLevels").select($option.text())})

After using the above code, I'm able to iterate the dropdown values. I can add other actions after selecting each dropdown value. cheers