Unable to retrieve ID of dropdown menu as the page reloads when I try to inspect elements

56 views Asked by At

Below is a screenshot of a webpage that I am trying to write a Cypress test for.

As you can see, I have managed to write "teladoc" into the input box, but I now need to click the dropdown menu to navigate to a different page.

I am not able to get the ID, etc. of the dropdown menu.

When I try to inspect the dropdown menu, the page reloads and the dropdown disappears.

Does someone know how I can inspect this? I tried through the cypress explorer too, but it reloads in that beforehand too.

enter image description here

2

There are 2 answers

0
Alapan Das On

Since the locator is not there, You can play around with Keypress. The idea is when you have typed and there is the suggested list, you can first press the down key and then enter key. This might result in flaky tests as you don't know how much time does it take for the suggested item to appear.

cy.get(selector).type('{downarrow}{enter}')

You can also directly use contains. If this works this way the tests won't be flaky. You can play around with the timeout value.

cy.contains('Teladoc Health Inc - United States', {timeout: 5000})
  .should('be.visible')
  .click()
0
mosaad On

Open the browser console and type this

setTimeout(() => { debugger; }, 5000)