英文:
How to iterate in Pagination drop down having values 10,25,50,100 in the drop-down using for loop
问题
Here is the translated code portion:
另一种迭代并选择所有下拉框值的方法
Select dropdown = new Select(WebUIDriver.webDr.findElement(By.xpath("输入xpath")));
int noOfDropDownValues = dropdown.getOptions().size() - 1;
for (int i = 0; i < noOfDropDownValues; i++) {
new Select(WebUIDriver.webDr.findElement(By.xpath("输入Xpath"))).selectByValue(String.valueOf(i));
}
英文:
Another method to iterate and select all the Dropdown values
Select dropdown= new Select(WebUIDriver.webDr.findElement(By.xpath("enter xpath")));
int noOfDropDownValues= dropdown.getOptions().size()-1;
for(int i=0;i<noOfDropDownValues;i++){
new Select(WebUIDriver.webDr.findElement(By.xpath("Enter Xpath']"))).selectByValue(String.valueOf(i));
}
答案1
得分: 1
使用Select类可能无法正常工作,因为它仅适用于带有Select标签的元素,但您可以尝试按索引选择它们,这将逐个选择下拉菜单中的所有选项。
Select dropdown = new Select(WebUIDriver.webDr.findElement(By.xpath("输入XPath")));
int noOfDropDownValues = dropdown.getOptions().size();
for (int i = 0; i < noOfDropDownValues; i++) {
dropdown.selectByIndex(i);
}
英文:
Without seeing the html code its hard to tell if using Select Class will work, as it only works with elements with Select Tag but you can try doing selecting them by index, this will select all options in dropdown one by one
Select dropdown = new Select(WebUIDriver.webDr.findElement(By.xpath("enter xpath")));
int noOfDropDownValues = dropdown.getOptions().size() ;
for (int i = 0; i < noOfDropDownValues; i++) {
dropdown.selectByIndex(i);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论