首页 > 解决方案 > 如何验证硒中的数组列表WebElement更大和最小值

问题描述

网站是黑暗的天空,我想验证当前温度是否大于或小于时间线中的温度。我使用了数组列表。我需要获取当前温度并将其与它们进行比较。谢谢你。我不能那样做。你对此有什么想法吗?谢谢。

ArrayList<WebElement> list = new ArrayList<>(SharedSD.getDriver( ).findElements(greaterOrLess));

标签: javaseleniumarraylistautomated-tests

解决方案


考虑测试的 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 ));

推荐阅读