- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to know the exact time to load a page using Selenium WebDriver?
We can determine the exact time to load a page using Selenium webdriver. We can capture the time before the page load with help of the System.currentTimeMillis method.
After the URL for the application is launched, we have to wait for the page to be loaded completely with the help of the explicit wait condition. Once the expected criteria for the element is met, we shall again record the current time.
The difference between the time recorded prior and post the page load will measure the exact time to load a page.
Syntax
long s = System.currentTimeMillis();
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class PageLoadTime{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); //capture time before page load long s = System.currentTimeMillis(); //URL launch driver.get("https://www.tutorialspoint.com/videotutorials/subscription.php"); //verify page is loaded WebDriverWait wt = new WebDriverWait(driver,6); wt.until(ExpectedConditions.elementToBeClickable (By.className("s-buy"))); //capture time after page load long e = System.currentTimeMillis(); //compute time long r = e – s; System.out.println("Page load time in milliseconds: " + r); driver.close(); } }
Output
- Related Articles
- How to set Page Load Timeout using C# using Selenium WebDriver?
- How to obtain the page title using Selenium webdriver?
- How to save and load cookies using Python Selenium WebDriver?
- Wait for complex page with JavaScript to load using Selenium.
- How to scroll the Page up or down in Selenium WebDriver using java?
- How to scroll down the page till page end in the Selenium WebDriver?
- How to scroll a Web Page using coordinates of a WebElement in Selenium WebDriver?
- How to wait for iFrames to load completely in Selenium webdriver?
- How to Scroll Down or UP a Page in Selenium Webdriver?
- How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?
- Get page title with Selenium WebDriver using Java.
- Getting the URL of the current page using Selenium WebDriver.
- How can I scroll a web page using selenium webdriver in python?
- How do you make Selenium 2.0 wait for the page to load?
- How to load a page in div using jQuery?

Advertisements