How i can select dropdown by its name in cypress?

Viewed 490
2 Answers

within() command "Scopes all subsequent cy commands to within this element". In other words, the callback in within() uses a DOM subtree starting at the element given by the command preceding within().

In your case, it's the element yielded by contains(postname) and you're getting an error because you're looking for .idea-row element inside this element.

Also, in your case, since the dropdown-menu element is not within the element yielded by contains(postname), you'll have to use contains() and within() this way:

cy.contains('.idea-row', potsname).within(()=>{
  cy.get('.drop-down-menu').click({force:true});
  cy.get('.drop-down-menu > .options-list').contains('Remove').click({force:true});
});
cy.contains('.idea-row', postname).within(($a)=>{
            // locate all of the spaces 
                if ($a.find('.drop-down-menu > .toggle > .zang-icon').length > 0) {   
                    cy.get('.drop-down-menu > .toggle > .zang-icon').click({force:true})
                    cy.get(' .drop-down-menu > .options-list > :nth-child(1) > .list-row > div > p')
                    .contains('Remove').click({force:true}) // click on "Edit Space" option of first newly created space drp dwn 

                }
            })

Above Solutions works for me

Related