Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
playwright conditional page.waitForNavigation

When automating a login for, I perform click on an element that it could lead to navigation to another page but in case of invalid password it will just display error message on the same page without actually causing a navigation.

I have tried:

await Promise.all([
      this.page.submitButton.click(),
      this.page.waitForNavigation()
    ]); 

But it will fail for the case when no navigation happens. I was thinking about interception the response, to check if the login succeed/failed, but may be there is a more clear way to do so ?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

This code should give you an example of how to understand if you stay on the same page or navigate:

await this.page.submitButton.click();

try {
    await this.page.waitForNavigation();
    // if we are here it means login was successful
} catch(e) {
    // if we are here it means login failed
}
about 4 years ago · Juan Pablo Isaza Relatório

0

I don't think you need some extra code besides this.page.submitButton.click().
The click function will wait for the navigation for you. So you could check after the click if your are in the same URL or not.

await this.page.submitButton.click(); // This will wait for a possible navigation

if(this.page.url() == destinationOnValidLogin) {
 // Good login stuff
} else {
 // Login failed
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda