如何使用Java计算Selenium WebDriver选择下拉框中的选项数量? [英] How to count the number of options in a select drop down box in Selenium WebDriver using Java?

查看:795
本文介绍了如何使用Java计算Selenium WebDriver选择下拉框中的选项数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用xpath // * [@ id =ddlTablePay]选择下拉列表。我需要计算这个下拉列表中的选项数量。谢谢

解决方案

使用 .getOptions() 方法并将它们存储在列表中。然后找到它的大小。

 选择se = new Select driver.findElement(By.id(select drop down locator))); 

列表< WebElement> l = se.getOptions();
l.size();

-Ajay


I have Select Dropdown list with xpath //*[@id="ddlTablePay"]. I need to count the number of options in this dropdown.Thank You

解决方案

Use .getOptions() method and store them in a list .Then find its size.

Select se = new Select(driver.findElement(By.id("select drop down locator")));

List<WebElement> l = se.getOptions();
l.size();

-Ajay

这篇关于如何使用Java计算Selenium WebDriver选择下拉框中的选项数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆