Collect networking data using Selenium WebDriver JavaScript Executer

Last updated on:

In my current project we are monitoring page loading time on Chrome browser by interacting directly with browser Console and retrieving from it information we need. Simply in console you can type:


Hit "Enter" and get information like the one bellow:

Here is simple explanation of request-response traveling.

For more information I would recomend read "Evaluating network performance"

Here is snippet of Selenium pageLoadTime() method I'm invoking every time new page is loaded. The data then gonna be collected and compared with preexisting data collection and throw a Warning in case there is significant increase of loading time. The result is not always mean something went wrong, but it is worse to pay attention and collect data.

public void pageLoadTime(){
		JavascriptExecutor js = (JavascriptExecutor) getCurrentDriver();

		long totalRequests = (Long) js.executeScript("return window.performance.getEntries().length;");
		System.out.println("Total requests to load the page is: " + totalRequests);

		long domLoadEventEnd = (Long) js.executeScript("return window.performance.timing.domContentLoadedEventEnd;");
		long fetchStart = (Long) js.executeScript("return window.performance.timing.fetchStart;");
		System.out.println("DOM Content Loaded: " + (domLoadEventEnd - fetchStart) + " ms.");

		long loadEventEnd = (Long) js.executeScript("return window.performance.timing.loadEventEnd;");
		System.out.println("Loaded: " + (loadEventEnd - fetchStart) + " ms.");
View Comments

Leave a Comment

Use markdown or basic HTML and be nice.