我们如何使用Selenium WebDriver获得加载页面的准确时间? [英] How can we get exact time to load a page using Selenium WebDriver?
问题描述
我们如何使用Selenium WebDriver获取加载页面的确切时间?
How can we get exact time to load a page using Selenium WebDriver?
我们使用Thread.sleep
We use Thread.sleep
我们使用implicitlyWait
We use implicitlyWait
我们使用WebDriverWait
we use WebDriverWait
但是我们如何才能获得使用加载页面的准确时间Selenium WebDriver?
but How can we get exact time to load a page using Selenium WebDriver?
推荐答案
如果您想知道使用Selenium WebDriver完全加载页面需要多长时间(又名Selenium 2)。
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).
通常,只有在页面完全加载后,WebDriver才会将控制权返回给你的代码。
Normally WebDriver should return control to your code only after the page has loaded completely.
因此,以下Selenium Java代码可以帮助您找到页面加载的时间 -
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);
这篇关于我们如何使用Selenium WebDriver获得加载页面的准确时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!