I am trying to perform a search for places in a search text field. While typing the place name, the system will display autocomplete of the places under the search field. I have written the test using trigger mousedown
in cypress to grab the autocomplete items.
describe('Search for places', function() {
it.only('Verify the search is working fine', function() {
cy.visit('url')
cy.get('#search-button').click();
cy.get('input[type="text"]').type("Salis");
//cy.get('input[placeholder="Start typing a suburb, city, station or uni"]').parents('.form-container').find('div').find('div').find('input').type("Salis");
cy.contains('span', 'bury, Brisbane').click();
//cy.get('.input-autocomplete').find('div.row').eq(0).click();
cy.get('div:contains(" Flatmates")').parents('.search-modes').find('div').find('div').contains(" Flatmates").click();
cy.get('a:contains("+ Advanced filters")').parents('.show-advanced-wrapper').find('p').find('a').click();
cy.get('#search-submit > div').contains("Search Flatmates").click();
cy.get('.section-heading > div > h1').invoke('text').then((text)=>{
const stext = text;
expect(stext).to.equal('Salisbury Housemates & Roommates');
})
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false
})
})
})
The test runs successfully in Cypress test runner (UI). But while running from the command line, it throws CypressError: Timed out retrying: Expected to find element: '.input-autocomplete'
, but never found it.
While inspecting the html of the autocomplete item, it disappears the autocomplete items, so unable to get the correcthtml
tags. Any idea what could be the reason for that error? Or any other stable way to get the autocomplete items.
Added the html
where cypress test fails while running from command line, see the screen shot below highlighted in red