0

HTML looks like below

<div id="ctl00_ContentColumnContent_PatientPanel" > 
    <span id="ctl00_ContentColumnContent_lblPatient" class="label required">
       Select a Patient:
    </span>

    <select name="ctl00$ContentColumnContent$ddlPatient" id="ctl00_ContentColumnContent_ddlPatient" class="select wide" size="10">
       <option value="0">**Delhi**</option>
       <option value="5422">Mumbai</option>
       <option value="326">Chennai</option>
    </select>

<span id="ctl00_ContentColumnContent_rfvPatient" style="color: red; visibility: hidden;">
   Field is required
</span>
</div>

I want to click on "Delhi".

Please guide me how to do this.

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
Pinakee
  • 5
  • 5

1 Answers1

0

Following should work -

// select the drop down list
var patient = driver.FindElement(By.Name("ctl00$ContentColumnContent$ddlPatient"));
//create select element object 
var selectElement = new SelectElement(patient );

// select by text
selectElement.SelectByText("**Delhi**");
Vikas Ojha
  • 6,742
  • 6
  • 22
  • 35
  • Thanks Vikas, it worked. Thanks a lot. And sorry for the confusion actually I copied and forgot to rename it as XPath. Will take care while posting any more queries. – Pinakee Jun 14 '15 at 14:51
  • No problem. I am glad it helped. Please select my answer as successful. – Vikas Ojha Jun 14 '15 at 18:02