在下拉列表(组合框)中,无法检查特定的值。在我的应用程序中,当我创建一个项目时,该项目将被添加到下拉列表中。当我删除该项目时,在下拉列表中不能使用相同的选项。那么,如何检查该项是否可供用户在selenium中选择?
编辑:添加了它的图片。这是一个AngularJS DropDown。

发布于 2016-12-15 18:24:15
粘贴代码,假设下拉列表已经使用简单的选择方法实现
String valueBeingChecked="xxxx";
int flag=0;
WebElement drpdwn=driver.findElement(by.id("DROPDOWN_ID");
Select DrpDwnSel=new Select(drpdwn);
List<WebElement> DrpDwnList=DrpDwnSel.getOptions();
For(WebElement indElem:DrpDwnList){
if (indElem.getText().contains(valueBeingChecked)){
Flag=1;
break;
}
}Flag=0,valueBeingChecked未上市
Flag=1,valueBeingChecked上市
发布于 2020-12-01 20:45:46
那是我的钱。我用的是尝试捕捉。当找不到选项时,它会更新标志。它比浏览清单要快。
public boolean isOptionExisted(String option) {
boolean result=true;
try {
Select selection= new Select(dropdownWebElement);
selection.selectByVisibleText(option);
}catch(Exception e) {
result = false;
}
return result;
}https://stackoverflow.com/questions/41168795
复制相似问题