Dropdown closes automatically
# i-need-help
q
I have a case in which I have to click on a dropdown, enter a search text in the search field and click on the option that matches the search text. The problem I have while using cypress is that the dropdown opens and immediately closes because of which the search term is not entered and the case fails. Can someone help me with what is going wrong here? I have tried adding wait() after click but it is not working. The logic I use here is: //click on dropdown(opens a list of elements with a search box) //wait //Enter search term in search box //Click on first option (because that is the only one matching the search term)
g
It will be hard to help without a reproducible example
s
cy.get("#Searchbox").type('group2'); cy.get('[id="Searchbox-listbox"]') .find("ul") .find("div") .contains('/^group2$/) .click(); I recently worked on a similar problem. I don't know why the dropdown immediately closes tho. For me I click on the searchbox directly. When you click on the dropdown list... does it automatically puts the focus on the searchbox or do you need to find the searchbox and click it before typing?
t
Have you tried using
then
? Something like cy.get('#dropdown').then( ($dropdown) => { //Find the searchbar and click it //Enter search term })
q
The focus is automatically on the search-box after the dropdown opens. And thanks, I'll try out the solution you have suggested 😃