我有一个预先选择了值的下拉菜单请帮我如何获取所选的值文本并在控制台中打印
下拉菜单html代码
<select id="ctl00_ContentPlaceHolder1_ddlCalculation" class="normalText"
style="width:100%;"
onchange="javascript:LoadMethods(this.value);
CallonChange(this.value,'spn_ddlCalculation');
return false;"
disabled="disabled" name="ctl00$ContentPlaceHolder1$ddlCalculation">
<option value="0" selected="selected">--- Select ---</option>
<option value="f">Formula Based</option>
<option value="m">Formula Based with Matrix Table</option>
<option value="q">Quantity Based</option>
<option value="t">Time Based</option>
</select>
答案 0 :(得分:0)
请尝试以下操作并告诉我它是否有效:
Select dropdown = new Select(driver.findElement("Use the correct selector");
WebElement option = dropdown.getFirstSelectedOption();
String content = option.getText();
System.out.println("selected Value " + content);