简体   繁体   中英

how to get HTML5 Application Cache Status by Selenium/Java

how to get HTML5 Application Cache Status by Selenium/Java

For Selenium/Java programming, how can the Selenium/Java get the status of the HTML5 Application cache status? I tried below, but it didn't work. "cannot be cast to org.openqa.selenium.html5.ApplicationCache.."

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.html5.AppCacheStatus;
import org.openqa.selenium.html5.ApplicationCache;

public class Html5AppCache {

    public void testHTML5LocalStorage() throws Exception {

        WebDriver driver = new FirefoxDriver();

        driver.get("http://www.w3schools.com/html/tryhtml5_html_manifest.htm");

        AppCacheStatus status = ((ApplicationCache) (driver)).getStatus();

    }

}

You are casting the short to AppCacheStatus object below, hence the error.

  AppCacheStatus status = ((ApplicationCache) (driver)).getStatus();

ApplicationCache is an interface so you have to write your own version of getStatus method.

You may want to get the cache status using the JavaScriptExecutor. Hope that helps.

JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
long cacheStatus = (long) jsExecutor.executeScript("return  window.applicationCache.status;");
System.out.println(cacheStatus);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM