0

i have a Drop Down menu which has pre-selected a value please help me how to get the selected value text and print it in console

drop down menu html code is

<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>
Yurii
  • 4,811
  • 7
  • 32
  • 41
Santhosh Siddappa
  • 708
  • 3
  • 14
  • 29
  • possible duplicate of [How to select/get drop down option in Selenium 2](http://stackoverflow.com/questions/6430462/how-to-select-get-drop-down-option-in-selenium-2) – Mickäel A. Feb 28 '14 at 10:15

1 Answers1

0

Please try the following and let me know if it works :

Select dropdown = new Select(driver.findElement("Use the correct selector");
WebElement option = dropdown.getFirstSelectedOption();
String content = option.getText();
System.out.println("selected Value " + content);
Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
Anand S
  • 760
  • 5
  • 13
  • 28