所有
我正在尝试在我的webdriver项目中使用Navigation Timing API。这是我尝试但它会抛出错误
public static Dictionary<String, Object> getTimingAPI(){
try{
Dictionary<String, Object> dict = new Hashtable<String, Object>();
dict = (Dictionary<String ,Object>) ((JavascriptExecutor)driver)executeScript("var performance = window.performance || window.webkitPerformance || window.mozPerformance || window.msPerformance || {}; var timings = performance.timing || {};return timings;");
return dict;
}catch (Exception e) {
System.err.println("Find browser timing : " + e);
}
return null;
}
错误: :
java.lang.ClassCastException: com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to java.util.Dictionary
我试图转换为String,Object等但总是抛出错误。我想知道这个java脚本的返回对象是什么。
感谢您的帮助。
答案 0 :(得分:1)
这种方式有效。
Map(String,Object)map = new HashMap(String,Object)();
map =(Map(String,Object))((JavascriptExecutor)驱动程序) .executeScript(JS_SCRIPT);
答案 1 :(得分:0)
我通过更改JS来返回个别时间并分配给对象,而不是返回所有时间来解决这个问题。
Object start = (Object) ((JavascriptExecutor) NavigationHelper.getWebDriver()).executeScript("var performance = window.performance || window.webkitPerformance || window.mozPerformance || window.msPerformance || {}; var timings = performance.timing.navigationStart || {};return timings;");
&#13;