mercredi 7 novembre 2018

Selenium - clicking button registered but not redirecting page to target link

I'm testing a web UI using Selenium in Java. I've come to a test case where a button which links to another page is supposed to be clicked right after loading a new page.

However, sometimes when the button is clicked, no page redirect is triggered. I'm sure that the button gets clicked correctly, as the button animation triggers and selenium proceeds the test, where it fails because it doesn't find any elements that are supposed to be on the next page.

One possible workaround would be a Thread.sleep() before clicking the button, but I'd like to avoid this solution.

I've tried this workaround where I check if redirect happened, but this just causes the page to loop and never actually load.

while(!driver.getCurrentUrl().toLowerCase().endsWith("login/checkout")) {
    driver.findElement(By.cssSelector("button[data-checkout-url='/cart/checkout']")).click();
}

Thank you for any advise.

Aucun commentaire:

Enregistrer un commentaire