0
votes

I would like to wait for the page to load completely. I know I could do this by waiting for a page element to load.

But I want something more generic, I assume that the Favicon can be used to determine if the page has loaded completely or not.

How do I determine if the FavIcon has loaded in a page using Selenium Webdriver?

"I understand it is just another element in your HTML source.But if you look into the page loading on any web page, Favicon would be the last one to get loaded. If there is a way to wait until the Favicon is loaded on a webpage, we can use that as a waitforpagetoload to test the entire application(Favicon will be the same on all webpages for an web application)."

1
The favicon is just another element in your HTML source.dokaspar
I understand it is just another element in your HTML source.But if you look into the page loading on any web page, Favicon would be the last one to get loaded. If there is a way to wait until the Favicon is loaded on a webpage, we can use that as a waitforpage to load to test the entire application.Karthick
Then just do it: seleniumDriver.findElement(By.xpath("..."));dokaspar

1 Answers

1
votes

I am not sure if waiting for favicon is a good idea. Different applications use different technologies and IMO there couldn't be a generic wait that could apply to all web applications. Below is what I use for 'my' applications. This gives you an idea. You would need to build what suits 'your' application.

public void my_generic_wait_for_page_load() {
 final WebDriverWait wait = new WebDriverWait(this.getDriver(), 300);
 final JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
 final ExpectedCondition<Boolean> jQueryActive_toBeZero = new ExpectedCondition<Boolean>() {
    @Override
    public Boolean apply(WebDriver driver) {
        try {
             return ((Long) jsExecutor
                            .executeScript("return jQuery.active") == 0) ? true
                            : false;
        } catch (final WebDriverException e) {
        log.warn("It looks like jQuery is not available on the page, skipping the jQuery wait, check stack trace for details",e);
            return true; //skip the wait
        }
    }
};
   final ExpectedCondition<Boolean> document_readyState_toBeComplete = new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driver) {
                return jsExecutor.executeScript("return document.readyState")
                        .toString().equals("complete") ? true : false;
            }
        };
        wait.until(jQueryActive_toBeZero);
        wait.until(document_readyState_toBeComplete);

 }