I have the following code which suppose the find a dropdown option:
Cypress.Commands.add('searchInDropDown', (searchedElement, containText, dropDownElement, eqValue = 0) => {
// Use the recurse function to navigate through the dropdown menu
recurse(
// The action to perform on each iteration
() => cy.contains(searchedElement, containText).should(() => { }),
// The condition to continue recursion
($option) => $option.length > 0,
// Options for the recurse function
{
limit: 100,
log: false,
timeout: 15000,
delay: 1000,
// The post function to execute after each successful iteration
post() {
// Simulate pressing the down arrow key on the dropdown menu
cy.get(dropDownElement).eq(eqValue).type('{downarrow}', { force: true })
}
}
// Force-click the selected option after the recursion is done
).click({ force: true })
})
For some reason it does not find it although I am sure it does contain it.
How can I log the current option value while searching for my value?
I tried this but got: Error
The function passed to cypress-recurse did not return a chainable instance. Did you forget the “return” command?
recurse(
// The action to perform on each iteration
($option) => {
if ($option) {
cy.log(`Comparing with: ${$option.text()}`);
cy.contains(searchedElement, containText).should(() => { });
}
},...

