How can we get exact time to load a page using Selenium WebDriver?

后端 未结 5 1655
感情败类
感情败类 2020-12-09 06:13

How can we get exact time to load a page using Selenium WebDriver?

We use Thread.sleep

We use implicitlyWait

we use WebDriverWait

but How can

5条回答
  •  被撕碎了的回忆
    2020-12-09 06:45

    If you are trying to find out how much time does it take to load a page completely using Selenium WebDriver (a.k.a Selenium 2).

    Normally WebDriver should return control to your code only after the page has loaded completely.

    So the following Selenium Java code might help you to find the time for a page load -

    long start = System.currentTimeMillis();
    
    driver.get("Some url");
    
    long finish = System.currentTimeMillis();
    long totalTime = finish - start; 
    System.out.println("Total Time for page load - "+totalTime); 
    

    If this does not work then you will have to wait till some element is displayed on the page -

     long start = System.currentTimeMillis();
    
    driver.get("Some url");
    
    WebElement ele = driver.findElement(By.id("ID of some element on the page which will load"));
    long finish = System.currentTimeMillis();
    long totalTime = finish - start; 
    System.out.println("Total Time for page load - "+totalTime); 
    

提交回复
热议问题