java - 如何验证硒中的数组列表WebElement更大和最小值
问题描述
网站是黑暗的天空,我想验证当前温度是否大于或小于时间线中的温度。我使用了数组列表。我需要获取当前温度并将其与它们进行比较。谢谢你。我不能那样做。你对此有什么想法吗?谢谢。
ArrayList<WebElement> list = new ArrayList<>(SharedSD.getDriver( ).findElements(greaterOrLess));
解决方案
考虑测试的 DarkSky:
Darksky 上的 Python 脚本:
刚刚将python代码转换为java
driver.get("https://darksky.net/forecast/40.7127,-74.0059/us12/en");
String currentTemp = driver.findElement(By.cssSelector(".summary.swap")).getText();
System.out.println("Current Temp:" + currentTemp);
List<WebElement> tempsInTimeLine = driver.findElements(By.cssSelector(".temps span:last-child"));
int temp = Integer.parseInt(currentTemp.substring(0, 2));
int highestInTimeLine = temp;
int lowestInTimeLine = temp;
for (WebElement tempInTime: tempsInTimeLine) {
String sLIneTemp = tempInTime.getText();
int lineTemp = Integer.parseInt(sLIneTemp.substring(0, 2));
if (lineTemp > highestInTimeLine){
highestInTimeLine = lineTemp;
}
if (lineTemp < lowestInTimeLine ){
lowestInTimeLine = lineTemp;
}
}
System.out.println("Highest Temp:" + Integer.toString(highestInTimeLine));
System.out.println("Lowest Temp:" + Integer.toString(lowestInTimeLine ));
推荐阅读
- php - 我们如何随机分配员工的职责
- spring-boot - JFROG Xray 可以扫描 Spring Boot Executable Jar 吗?
- android - 在 viewpager 中显示预选项目
- java - Spring Boot Security OAuth SSO 和 Keycloak:获取用户详细信息时重定向过多
- powershell - PowerShell:切片和骰子制表符分隔文件
- javascript - JavaScript 过滤数组中的数据
- java - Android 应用程序中的 EULA 对话框
- javascript - 在文本选择之前和之后添加标记(jquery)
- maven - 将 localRepository 移动到另一台计算机会下载太多
- ruby-on-rails - 商品未添加到购物车