我试图比较列表中包含此定位符的所有元素: 70.000
我已经尝试使用AssertJ,但它不起作用:
List<WebElement> listaPret = driver.findElements(By.className("pret-mare"));
for (int i = 0; i < listaPret.size(); i++){
assertThat(i).isBetween(50.000,80.000);
}
添加我尝试检查此内容的网页 https://www.imobiliare.ro/vanzare-apartamente/timisoara?id=6923228
我对硒和自动化测试非常陌生,包括编程,所以请耐心等待:D
答案 0 :(得分:2)
试试这个:
List<WebElement> listaPret = driver.findElements(By.className("pret-mare"));
assertThat(listaPret.size()).isBetween(50.000,80.000);
如果您尝试从listaPret获取号码,请使用此:
List<WebElement> listaPret = driver.findElements(By.className("pret-mare"));
for (int i = 0; i < listaPret.size(); i++){
double price = Double.parseDouble(listaPret.get(i).getText());
assertThat(price).isBetween(50.000,80.000);
}
正如@mrfreester建议的那样,每个循环使用更安全(也更好看):
List<WebElement> listaPret = driver.findElements(By.className("pret-mare"));
for (WebElement item : listaPret) {
double price = Double.parseDouble(item.getText());
assertThat(price).isBetween(50.000,80.000);
}