我正在尝试选择0(5Gallon)选项,但我得到元素不可见异常。
请注意:Wait
语句已添加。
<Select id="attrValue_ATT_calc_size__volume_or_weight_+_item_" onchange="JavaScript:productDisplayJS.hideMessage();productDisplayJS.setSKUImageId("productMainImage");productDisplayJS.setSelectedAttribute("Size",this.value, "entitledItem_261730"); productDisplayJS.notifyAttributeChange("261730","entitledItem_261730",false,true);productDisplayJS.updatePriceInfo("261730");productDisplayJS.updateItemDetails("entitledItem_261730");" style="display: none;">
<option value="5 Gallon"> 5 Gallon</option>
<option value="1 Gallon" selected="selected">1 Gallon</option>
</select>
我正在使用
I am using this function for selectdropbyindex
public boolean selectDropdownItemByIndex(WebElement ddElement, int index) {
boolean success = true;
softAssert.setCause(null);
try {
Select selectElement = new Select(ddElement);
int optionCount = selectElement.getOptions().size();
(selectElement).selectByIndex(index);
} catch (Exception | Error e) {
ConsoleLog.error("Selecting an item in a dropdown Select menu did not work as expected.", e);
}
答案 0 :(得分:0)
试试这个
new Select(driver.findElement(By.id("attrValue_ATT_calc_size__volume_or_weight_+_item_"))).selectByIndex(0);