如何使用Selenium C#单击容器列容器中的文本?

时间:2015-06-13 18:49:54

标签: c# selenium

HTML如下所示

<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>

我想点击“德里”。

请指导我如何做到这一点。

1 个答案:

答案 0 :(得分:0)

以下应该工作 -

// 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**");