我看到Selenium 2现在支持WebDriverEventListener,但事件似乎并不是浏览器DOM的事件。有没有办法从我的Java测试框架中检测DOMContentLoaded?
答案 0 :(得分:0)
事实证明,您可以使用新的Web计时API:
System.setProperty("webdriver.chrome.driver","/home/joel/dev/libs/chrome-web-driver/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
JavascriptExecutor js =((JavascriptExecutor) driver);
Object val = js.executeScript("" +
"try{window.performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {};" +
"return(parseInt(window.performance.timing.domContentLoadedEventEnd)-parseInt(window.performance.timing.navigationStart));}catch(e){alert(e);}");
System.out.println(val.toString());