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 加载页面的准确时间?
基础教程推荐
- JPA惰性列表上的流 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
