在selenium中使用java选择复选框值
我需要从给定的附件中选择一个复选框值 问题是它不是这样设计的,我可以选择特定值的id 我想在Material块下找到元素的在selenium中使用java选择复选框值,java,selenium,checkbox,Java,Selenium,Checkbox,我需要从给定的附件中选择一个复选框值 问题是它不是这样设计的,我可以选择特定值的id 我想在Material块下找到元素的列表,然后选择值cotton 我对selenium非常陌生,我尝试先使用以下代码显示元素: List<WebElement> materialList = driver.findElements(By.id("ref_3248233031")); boolean materiaListIsdisplayed = ((WebElement) materialList
列表
,然后选择值cotton
我对selenium非常陌生,我尝试先使用以下代码显示元素:
List<WebElement> materialList = driver.findElements(By.id("ref_3248233031"));
boolean materiaListIsdisplayed = ((WebElement) materialList).isDisplayed();
System.out.println("Material Block is displayed" +materiaListIsdisplayed);
//System.out.println(materialList.getText()); String checkBoxEachValue = ((WebElement) materialList.get(0)).getAttribute("value");
System.out.println(checkBoxEachValue);
List materialList=driver.findElements(By.id(“ref绢3243031”);
布尔materiaListIsdisplayed=((WebElement)materialList).isDisplayed();
系统输出打印项次(“显示物料块”+显示物料);
//System.out.println(materialList.getText());String checkBoxEachValue=((WebElement)materialList.get(0)).getAttribute(“值”);
System.out.println(checkBoxEachValue);
但它不断给出以下例外情况:
线程“main”java.lang.ClassCastException中的异常:
无法将java.util.ArrayList转换为org.openqa.selenium.WebElement
在
com.jahira.addtocart.searchBedsheets.filterBedsheets(searchBedsheets.java:57)
在
com.jahira.addtocart.searchBedsheets.main(searchBedsheets.java:121)
请告诉我我犯了什么错误,并帮助选择复选框的值表单列表。请尝试下面的代码片段
List <WebElement> materialList = driver.findElements(By.id("ref_3248233031"));
For(WebElement elem:materialList ){
if(elem.getAttribute("value").equalsIgnoreCase("cotton"){
elem.click;
break;
}
}
List materialList=driver.findElements(By.id(“ref绢3243031”);
For(WebElement元素:materialList){
if(elem.getAttribute(“value”).equalsIgnoreCase(“cotton”){
元素单击;
打破
}
}
您的列表应该是类型安全的list materialList=…
遵循下面的url请正确设置代码和异常详细信息的格式。是的..感谢您的代码片段…但它在线程“main”中给出了下面的异常java.lang.IndexOutOfBoundsException:Index:1,Size:1我怀疑所选的是否有误。我的HTML内容如下材料html
代码段。如果您试图检查复选框的特定值,则该复选框应仅位于
标记中,则您可以通过单击任何ul
或li
标记来检查该复选框