Wait for a page to be loaded after cy.click()
#27243
Answered
by
adnanerlansyah403
hamidmayeli
asked this question in
Questions and Help
-
I have the following code: Cypress.Commands.add("login", (username: string, password: string) => {
cy.get("a").contains("Login").click(); // this line takes the user to a new page
cy.get("label").contains("Username").next("input").type(username);
cy.get("label").contains("Password").next("input").type(password);
cy.get("button").contains("Login").click();
}); After simulating the first click, user should be taken to a new page, however, the next line happens before loading. I have tested a solution that I could find (calling Is there a way to wait for the new page? Something like: cy.waitToSee(cy.get("label").contains("Username")); |
Beta Was this translation helpful? Give feedback.
Answered by
adnanerlansyah403
Dec 5, 2023
Replies: 1 comment
-
you can use the ones event of cypress, like this : cy.on('url:changed', (url) => { |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
hamidmayeli
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can use the ones event of cypress, like this :
cy.on('url:changed', (url) => {
// will get the new currentUrl from callback while the url was changed
})