当我将webdriver javascriptExecutor强制转换为Dictionary时,键入强制转换错误

时间:2014-10-29 09:23:19

标签: webdriver navigation-timing-api

所有

我正在尝试在我的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脚本的返回对象是什么。

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

这种方式有效。

Map(String,Object)map = new HashMap(String,Object)();

map =(Map(String,Object))((JavascriptExecutor)驱动程序)           .executeScript(JS_SCRIPT);

答案 1 :(得分:0)

我通过更改JS来返回个别时间并分配给对象,而不是返回所有时间来解决这个问题。

&#13;
&#13;
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;
&#13;
&#13;