Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

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

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 we get exact time to load a page using Selenium WebDriver?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...