- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Dynamic Dropdown verification with Cypress
There are numerous types of dropdowns on the webpage. The types of dropdowns are static and dynamic. While the static dropdowns have with the <select> tag, the dynamic dropdowns generally have the <input> or <ul> tags.
The static dropdowns having the <select> tag is handled in Cypress with the help of the in built command called the select(). The dynamic dropdowns are mostly the auto suggestive dropdown where on typing the first few letters of our search, a list of suggested items get displayed.
The logic is to type a few characters inside the dynamic dropdown. Based on that a list of suggestions will be displayed. We shall iterate through that list. Once we encounter our desired option, we will perform the click() operation on it.
Example
Code Implementation with Dynamic dropdown.
// test suite describe('Tutorialspoint Test', function () { // test case it('Test Case1', function (){ // test step to launch a URL cy.visit("https://www.tutorialspoint.com/videotutorials/index.php"); // enter test in the dynamic dropdown cy.get("#search-strings").type("Java"); // wait for some time cy.wait(3000); // assertion to validate the number of search results cy.get('.clsHeadQuestion'). should('have.length',19); // iterate through the suggested options cy.get('.clsHeadQuestion').each(($el, index, $list) => { // condition matching check if($el.text() ==="Java"){ // click() on that option for selection $el.click(); } }) // assertion to check if correct option is selected cy.get("#search-strings").should("have.value","Java"); }); });
- Related Articles
- Static Dropdown verification with Cypress
- Checkbox verification with Cypress
- Verification and Validation with Example
- Handling Alerts with Cypress
- Handling Frames with Cypress
- Handling Child Tabs with Cypress
- Handling Web Tables with Cypress
- Mouse over Actions with Cypress
- Handling Child Windows with Cypress
- Create Dropdown menu with Bootstrap
- Tabs With Dropdown Bootstrap Example
- Handling with only visible elements in Cypress
- Disable a dropdown item with Bootstrap
- Tkinter dropdown Menu with keyboard shortcuts
- Verification in Java (JVM)
