我们如何获得使用 Selenium WebDriver 加载页面的准确时间? [英] How can we get exact time to load a page using Selenium WebDriver?

查看:55
本文介绍了我们如何获得使用 Selenium WebDriver 加载页面的准确时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何获得使用 Selenium WebDriver 加载页面的准确时间?

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

我们使用 Thread.sleep

We use Thread.sleep

我们使用隐式等待

我们使用 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆