首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何利用Selenium/Java获取HTML5应用程序缓存状态

如何利用Selenium/Java获取HTML5应用程序缓存状态
EN

Stack Overflow用户
提问于 2015-06-20 11:41:29
回答 1查看 657关注 0票数 0

如何利用Selenium/Java获取HTML5应用程序缓存状态

对于Selenium/Java编程,Selenium/Java如何获得HTML5应用程序缓存状态的状态?我在下面试过了,但不起作用。“无法转换为org.openqa.selenium.html5.ApplicationCache。”

代码语言:javascript
复制
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();

    }

}
EN

回答 1

Stack Overflow用户

发布于 2015-06-20 15:03:38

您正在将short强制转换为下面的AppCacheStatus对象,因此出现错误。

代码语言:javascript
复制
  AppCacheStatus status = ((ApplicationCache) (driver)).getStatus();

ApplicationCache是一个接口,因此您必须编写自己版本的getStatus方法。

您可能希望使用JavaScriptExecutor获取缓存状态。希望这能有所帮助。

代码语言:javascript
复制
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
long cacheStatus = (long) jsExecutor.executeScript("return  window.applicationCache.status;");
System.out.println(cacheStatus);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30950020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档