4

Here I am using cypress tool for automation. How to write code for dropdown menu

drop down with search box and select button

Here is the HTML code html code

I just done like this way but its not working

cy.get('.dropdown-heading-dropdown-arrow').click()
cy.get('#0').click()
4
  • can you add the html code of your dropdown to the question. And also post the code that you tried? Commented Sep 20, 2021 at 11:21
  • @AlapanDas please check sir..... Commented Sep 20, 2021 at 12:22
  • Your html doesn't have the code for any of the dropdown values. can you add that? Commented Sep 20, 2021 at 12:24
  • @AlapanDas this dropdown listing is based on the previously created data for feature, if we create a new feature, then next page dropdown features shows- last created datas, we need to select from that Commented Sep 20, 2021 at 12:38

2 Answers 2

6

After dropdown opens search for the option with required text.

Not sure which selector might work for you, either role or .MuiMenuItem-root looks best, or try just getting any element with the text

cy.get('.dropdown-heading-dropdown-arrow').click()

cy.contains('[role="option"]', 'Select All')      
  .click()

// or

cy.contains('.MuiMenuItem-root', 'Select All')      
  .click()

// or

cy.contains('Select All')
  .click()
Sign up to request clarification or add additional context in comments.

Comments

3

Have a look at this. Gives a good explanation as well.

select dropdownlist item using cypress

Otherwise you can just get it by css selector, xpath or you can do cy.contains

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.