how to measure response time for both loading and search time for a website ? selenium how to measure response time for both loading and search time for a website ? selenium selenium selenium

how to measure response time for both loading and search time for a website ? selenium


You can use selenium web driver to gather the timing data about your web page. Just do this:

from selenium import webdriversource = "http://www.example.com/"driver = webdriver.Chrome()driver.get(source)navigationStart = driver.execute_script("return window.performance.timing.navigationStart")responseStart = driver.execute_script("return window.performance.timing.responseStart")domComplete = driver.execute_script("return window.performance.timing.domComplete")backendPerformance = responseStart - navigationStartfrontendPerformance = domComplete - responseStartprint "Back End: %s" % backendPerformanceprint "Front End: %s" % frontendPerformancedriver.quit()


You can get the timing-related performance information for a given page with the performance.timing API:

// launch the browserWebDriver driver = new FirefoxDriver();// visit a pagedriver.get("http://stackoverflow.com");// get the  page load timeLong loadtime = (Long)((JavascriptExecutor)driver).executeScript(    "return performance.timing.loadEventEnd - performance.timing.navigationStart;");

The doc :

https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming


Selenium doesn't provide a better way to do this. The way you are using it is the best way possible as far as I know.For the search method you can use the same way as you used for the page loading. Except you'd be doing some different actions between the start and stop time.

Also take a look at this question as I believe it answers your question.How can we get exact time to load a page using Selenium WebDriver?