我有选择下拉列表:
xpath //*[@id="ddlTablePay"]
我需要计算此下拉菜单中的选项数量。谢谢
答案 0 :(得分:9)
使用.getOptions()
方法并将其存储在列表中。然后找到它的大小。
Select se = new Select(driver.findElement(By.id("select drop down locator")));
List<WebElement> l = se.getOptions();
l.size();
-Ajay
答案 1 :(得分:2)
使用.getXpathCount()
方法
int numOptions = selenium.getXpathCount("//*[@id='ddlTablePay']/option").intValue();
答案 2 :(得分:2)
String[] options = driver.findElement(By.id("dropdown")).getText().split("\n");
options.length;
答案 3 :(得分:0)
optionItems = Select(driver.find_element_by_xpath("//select[@id='ddlTablePay']"))
print "Total Elements " + str(len(optionItems.options))
答案 4 :(得分:0)
//计算选项数量
Select dropDown = new Select(driver.findElement(By.id("ddlTablePay")));
List<WebElement> elementCount = dropDown.getOptions();
System.out.println("Number of items: " + elementCount.size());
//获取并打印所有选项
Select dropDown = new Select(driver.findElement(By.id("ddlTablePay")));
List <WebElement> elementCount = dropDown.getOptions();
int itemSize = elementCount.size();
for(int i = 0; i < itemSize ; i++){
String optionsValue = elementCount.get(i).getText();
System.out.println(optionsValue);
}
答案 5 :(得分:-2)
Select selection = new Select(driver.findElement(By.id(“ Drop down id”)));
int size = selection.getOptions()。size();