How can we get exact time to load a page using Selenium WebDriver?(我们如何获得使用 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 加载页面的准确时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我们如何获得使用 Selenium WebDriver 加载页面的准确时间?
基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
