如何利用Selenium/Java获取HTML5应用程序缓存状态
对于Selenium/Java编程,Selenium/Java如何获得HTML5应用程序缓存状态的状态?我在下面试过了,但不起作用。“无法转换为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();
}
}发布于 2015-06-20 15:03:38
您正在将short强制转换为下面的AppCacheStatus对象,因此出现错误。
AppCacheStatus status = ((ApplicationCache) (driver)).getStatus();ApplicationCache是一个接口,因此您必须编写自己版本的getStatus方法。
您可能希望使用JavaScriptExecutor获取缓存状态。希望这能有所帮助。
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
long cacheStatus = (long) jsExecutor.executeScript("return window.applicationCache.status;");
System.out.println(cacheStatus);https://stackoverflow.com/questions/30950020
复制相似问题