How to find response time of a website using selenium?

By | 12th Jan 2015 | 1 min read

In websites response time play a very important roles. Capturing this time is a difficult task. We can perform this by selenium Framework and by using the below script we can calculate the response time. The main aim of the script is to find time taken for JavaScript code execution, elements loading, page load etc.
In this code we can calculate the time span between two events in different case.

We can use two different timers to find response time, if we want to find the response time of a page load we can use two variables start time and end time. most probably the start time belongs to be system time System.currentTimeMillis() or server time.

Script:


long startTime = System.currentTimeMillis();
driver.get("http://zyxware.com");
new WebDriverWait(driver, 10).until(ExpectedConditions.
presenceOfElementLocated(By.id("Calculate")));
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
System.out.println("Total Page Load Time: " + totalTime + "
milliseconds");

Though this is not a perfect approach, it will give us a good measure of the page load time.