我有一个网页下拉选择一个国家,已使用jQuery选择插件呈现。下面的HTML的提取物,CssSelector Webdriver FindElement点击不工作
<div>
<label for="phMainContent_EmployeeAdd1_ddlCountry" id="phMainContent_EmployeeAdd1_lblCountry" class="short required">Country*</label>:
<div id="phMainContent_EmployeeAdd1_ddlCountry_chzn" class="chzn-container undefined chzn-container-single" style="width: 199.44444px;">
<a href="#x" class="chzn-single"><span>Please select ...</span><div><b></b></div></a>
<div class="chzn-drop" style="left: -9000px; width: 197.222px; top: 28px;">
<div class="chzn-search"><input type="text" style="width: 162px;"></div>
<ul class="chzn-results">
<li id="phMainContent_EmployeeAdd1_ddlCountry_chzn_o_0" class="active-result result-selected">Please select ...</li>
<li id="phMainContent_EmployeeAdd1_ddlCountry_chzn_o_1" class="active-result">United Kingdom</li>
<li id="phMainContent_EmployeeAdd1_ddlCountry_chzn_o_2" class="active-result">Afghanistan</li>
.......
如果我使用硒IDE录制的动作,从下面的脚本被记录在列表中选择“联合王国”。运行代码片段以查看其中的命令。
<table border="1">
<tr>
<td>Command</td>
<td>Target</td>
</tr>
<tr>
<td>click</td>
<td>css=a.chzn-single > span</td>
</tr>
<tr>
<td>click</td>
<td>id=phMainContent_EmployeeAdd1_ddlCountry_chzn_o_1</td>
</tr>
</table>
我可以在IDE中重复运行此脚本和英国从下拉每次选择。但是,如果我出口的C#/ NUnit的/ webdriver的代码下面
driver.FindElement(By.CssSelector("a.chzn-single > span")).Click();
driver.FindElement(By.Id("phMainContent_EmployeeAdd1_ddlCountry_chzn_o_1")).Click();
并执行它,它失败与硒元素不可见例外一号声明。
有关如何解决此问题的任何建议?
这可能是一个时间问题之前,为了确保下拉是可见的。尝试插入一个Thread.sleep(2000);声明之间。请注意,该声明采用Java语言。 – rs79