java - 无法在我的控制台中打印下拉选项文本
问题描述
WebElement AllDeptDropDown = driver.findElement(By.cssSelector("#search-in-dept"));
Select s = new Select(AllDeptDropDown);
List<WebElement>DrpDownOption = s.getOptions();
System.out.println("Total All Dropdown otions are - " + DrpDownOption.size());
for (WebElement i : DrpDownOption) {
System.out.println("DorpdownOptions Texts are - " +i.getText());
}
控制台输出:
Total All Dropdown otions are - 30
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
DorpdownOptions Texts are -
PASSED: ShopSite
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
解决方案
如果您想在下拉列表中打印所有选项,那么您可能想使用此代码:
Select s = new Select(Webelement of select tag);
List<WebElement> allOptions = driver.findElements(By.xpath("xpath for all options may be a class name"));
for(WebElement options : allOptions){
System.out.println(options.getText());
}
推荐阅读
- flutter - GetX Get.toNamed() 忽略 Navigator 上的 onGenerateRoute
- python-3.x - 如何在 python 中操作 spark 数据框?
- cassandra - cassandra local_quorum 查询不一致
- reactjs - 我无法让影子在我的搜索栏上工作
- java - 如何在jooq中处理带有特殊字符的like子句,例如_,\,%
- python - opencvstitcher.stitch函数解释
- python - 在正确计算源代码中的关键字时无法获得计数器
- java - 测试 Optional.map() 时的 Mockito 错误?
- beautifulsoup - 使用 BS4 抓取信息
- c# - 如何检查 Xamarin Forms 中的位置服务是否“开启”?