我需要从下面的 html 中选择一个类别。我尝试了不同的选项,并且在博客中显示了不同的方式,但无法选择选项。任何帮助将不胜感激。
我使用的一种方式(不是更好的方式)
private boolean select_dropdown_xpath(String value, String seleniumObjectValue) {
try {
boolean isListItemFound = false;
int i = 0;
do {
i++;
String category = driver.findElement(By.xpath(seleniumObjectValue+"/div["+ i +"]")).getText();
if(category.equals(value)) {
driver.findElement(By.xpath(seleniumObjectValue+"/div["+ i +"]")).click();
isListItemFound = true;
}
} while (isListItemFound == false);
if(!(isListItemFound)) {
return false;
}
} catch(Exception e) {
return false;
}
return true;
}
工具:Selenium WebDriver 2.28 with Java
谢谢普纳
HTML:
<div class="drop-down">
<div class="label_field">
<label>Category:</label>
<fieldset>
<div id="Ccategory" class="jSym_select_element jSym_pie jSym_noSelectText false hover" tabindex="0" textval="Default" style="width: 350px;">
<div class="jSym_drop_arrow false"/>
<div class="jSym_select_inner false">Default</div>
</div>
<div id="selectDrop" class="jSym_select_drop jSym_noSelectText " style="height: 50px; width: 350px; margin-top: 10px;">
<div class="jSym_select_item jSym_noSelectText" optionval="Default">Default</div>
<div class="jSym_select_item jSym_noSelectText" optionval="Reset">Reset</div>
</div>
<select id="select_category" class="jSym_dropdown" name="category" style="visibility: hidden;">
<option value="Default">Default</option>
<option value="Reset">Reset</option>
</select>
</fieldset>
</div>
</div>