从硒中的下拉值中读取选项文本 [英] Read option text from drop down values in selenium
本文介绍了从硒中的下拉值中读取选项文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
List<WebElement> statusvalues = driver.findElements(By.id("ddlStatus"));
for (WebElement option : statusvalues)
{
System.out.println(option.getText());
}
这是我曾经写过的脚本.
This is the script I have used to write.
系统未提供错误,但我没有得到结果.我需要在输出中写入五个下拉值. HTML
代码如下.
System not providing the error but I didn't get the result. There are five drop down values I need to write in the output. The HTML
code is given below.
<select id="ddlStatus" name="Status" class="full-width" data-role="dropdownlist" style="display: none;">
<option value="" selected="selected"> -- Select -- </option>
<option value="11">Arts</option>
<option value="13">Science</option>
<option value="14">Engineering</option>
<option value="64">Law</option>
<option value="85">Teaching</option>
<option value="87">Journalist</option>
</select>
仅研究Selenium Webdriver以及如何在输出中写入下拉值.
Just exploring the selenium webdriver and how to write the drop down values in the output.
推荐答案
List<WebElement> statusvalues = driver.findElements(By.id("ddlStatus"));
这是一个元素,而不是元素的集合,因此您需要这样做:
it's an element and not collection of elements so you need to do:
WebElement selectElement = driver.findElement(By.id("ddlStatus"));
在该元素中,您可以选择进行收集:
In that element you have options so you can make collection:
List<WebElement> options = selectElement.findElements(By.tagName("option"));
现在您可以循环播放...
and now you can loop...
尝试:
List<WebElement> statusvalues = driver.findElement(By.id("ddlStatus")).findElements(By.tagName("option"));
for (WebElement option : statusvalues)
{
System.out.println(option.getText());
}
这篇关于从硒中的下拉值中读取选项文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文