vendredi 24 novembre 2017

Selenium: pageLoadTimeout() not working on deeper links under slow network

My practice of speeding up Selenium test under slow network is to use pageLoadTimeout().

    try {
        driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
        driver.get(url);
    }
    catch (TimeoutException e){
    }
    finally {
        driver.findElement(By.xpath("xpath here")).click();
    }

However this won't work if you're trying to click another link and then a new page loads. You're will soon get

org.openqa.selenium.TimeoutException

because the code didn't handle the new page's timeout exception.

This will get trickier if there're a lot of links you have to go thru before you are actually reaching the page you wanna test.

Does anyone has a solution to this?

(It's driving me crazy!! You have to understand the network here in China can be really messed up sometimes. It could take literally forever to load the page when you're visiting foreign websites.)

Aucun commentaire:

Enregistrer un commentaire