Is there a way to wait for existence of an element in regular intervals, without failing #30164
Unanswered
DarshanS4444
asked this question in
Questions and Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Scenario -
getLatestDetails(attempts = 5): Cypress.Chainable<JQuery> {
const checkDetails = (attemptsLeft: number): Cypress.Chainable<JQuery> => {
if (attemptsLeft === 0) { throw new Error(
Details not found after maximum attempts.
) }return cy.wait(10000).then(() => {
this.search() // search method for new entry
return cy.xpath(
//Dynamic xpath for element
, { timeout: 0 }).then($element => {if ($element.length) {. return cy.wrap($element) }
else { return checkDueDetails(attemptsLeft - 1) }
})
})
}
Above is my method in cypress typescript automation, where i am fetching latest details by searching the data.
But for the data to be shown it takes time based on the server. 10secs, 22secs, 15secs, etc.
I want to give a solution to it by having a repeated loop of 5 times where i wait for 10 sec in each loop and check if the element exists.
Problem statement - The script is not waiting in regular intervals and fails with timeout error as below
Timed out retrying after 4000ms: Expected to find element: "element xpath", but never found it.
Solution required - Approach to wait for the existence of element in regular intervals until the element is found.
Beta Was this translation helpful? Give feedback.
All reactions