有人可以帮我处理以下情况: 我有以下元素的Webelement列表:
Double Chance (Ordinary Time)
1X2 (Ordinary Time)
12 (Full Event)
Odd/Even (Full Event)
Over / Under (Full Time)
Odd/Even (Ordinary Time)
Halftime / Fulltime (Ordinary Time)
Over Under (Ordinary Time)
1X2 (1st Half)
Odd/Even (1st Half)
我必须确认它们之间存在,即1X2(普通时间),如果存在,那么只是为了使用它。如果不存在,请完成测试。下面是我尝试的代码,但没有成功:
List<WebElement> allAvailsbleMarkets = driver.findElements(By.xpath("//main[@class='be-root__main']/be-match2/be-single-view-layout/div[3]
for (int p = 0; p < allAvailsbleMarkets.size(); p++) {
System.out.println(allAvailsbleMarkets.get(p).getText());
}
if (allAvailsbleMarkets.contains("1X2 (Ordinary Time)")) {
"GO to that element"
} else {
System.out.println("chosen Bet Type is not in the list of offered ones");
}
不幸的是,我总是得不到那个元素。我做错了什么?
@ f1sh检查所有选项,我只需要一个:
Tip can not be posted
Tip can not be posted since that chosen Bet Type is not in the list of offered ones
Tip can not be posted since that chosen Bet Type is not in the list of offered ones
Tip can not be posted since that chosen Bet Type is not in the list of offered ones
Tip can not be posted since that chosen Bet Type is not in the list of offered ones
And until it finish counting
答案 0 :(得分:2)
您检查List
个WebElement
包含String
。这将永远是错误的,因为它包含WebElement
类型的项目。
检查每个WebElement,如果它的getText()
方法返回的值为equals
您想要的String
:
for(WebElement e:allAvailsbleMarkets){
if("1X2 (Ordinary Time)".equals(e.getText())){
//go to that element
//an element has been found, so stop the checking loop:
break;
}
}