这是我的代码:
WebElement pooldropdown=driver.findElement(By.xpath("/html/body/section/section[2]/div[1]/select"));
Select sel = new Select(pooldropdown);
List<WebElement> list = sel.getOptions();
System.out.println("Number of Pool items : "+list.size());
for(int i =0; i>list.size() ; i++){
System.out.println(list .get(i).getText());
}
HTML代码:
<section id="content-data"><div class="cpoolSelection" id="poolSelection"><div class="cpoolLabel" id="poolLabel">Select Pool : </div><select onchange="callSetPoolId()" id="poolFilter" style="display: none;"><option value="0"> All </option><option selected="true" value="1">National</option><option value="2">Special Reserve</option><option value="3">NAT_PERM</option><option value="4">NE_PERM</option><option value="5">SE_PERM</option><option value="6">NC_PERM</option><option value="7">SC_PERM</option><option value="8">SCNW_PERM</option><option value="9">NC4C_PERM</option><option value="10">RSC_PERM</option><option value="11">A&D_PERM</option><option value="12">FCP</option><option value="13">R&D</option><option value="14">Support</option><option value="15">Other</option><option value="17">RSA Lease</option></select><button class="ui-multiselect ui-widget ui-state-default ui-corner-all poolClass ui-state-active" type="button" aria-haspopup="true" style="width: 228px;">
<span class="ui-icon ui-icon-triangle-1-s"></span>
<span>National</span>
</button>
</div>
&#13;
我无法使用上面的selenium代码选择下拉值。 请帮我从下拉列表中选择值并验证下拉列表中的所有选项。
答案 0 :(得分:0)
请改进您的for循环代码:
for(int i =0; i>list.size() ; i++){
System.out.println(list .get(i).getText());
}
到
for(int i = 0; i < list.size() ; i++){ //observe the sign change
System.out.println(list .get(i).getText());
}
答案 1 :(得分:0)
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);