【发布时间】:2019-01-02 21:41:16
【问题描述】:
**HTML:**
<div id="ctl05_ctl03_cblUser" class="RadComboBox RadComboBox_Silk"
style="width:250px;white-space:normal;">
<table summary="combobox" border="0" style="border-width:0;border-
collapse:collapse;width:100%" class="">
<tbody>
<tr>
<td class="rcbInputCell rcbInputCellLeft" style="width:100%;">
<input name="ctl05$ctl03$cblUser" type="text" class="rcbInput
radPreventDecorate" id="ctl05_ctl03_cblUser_Input" value="" autocomplete="off">
</td>
<td class="rcbArrowCell rcbArrowCellRight">
<a id="ctl05_ctl03_cblUser_Arrow" style="overflow: hidden;display:
block;position: relative;outline: none;">select
</a>
</td>
</tr>
</tbody>
</table>
<input id="ctl05_ctl03_cblUser_ClientState"
name="ctl05_ctl03_cblUser_ClientState" type="hidden" autocomplete="off">
</div>
<div class="rcbSlide" style="z-index: 6000; display: block; width: 250px;
top: 362.594px; left: 247px; overflow: visible;">
<div id="ctl05_ctl03_cblUser_DropDown" class="RadComboBoxDropDown
RadComboBoxDropDown_Silk " style="width: 248px; display: block; top: 0px;
visibility: visible; transition: none;">
<div class="rcbScroll rcbWidth" style="height: 345px;">
<ul class="rcbList">
<li class="rcbItem">
<label>
<input type="checkbox" class="rcbCheckBox">John, Smith</label>: :after
</li>
<li class="rcbItem"><label>
<input type="checkbox" class="rcbCheckBox">Jane, Dow</label>: :after
</li>
</ul>
</div>
</div>
在此处添加注释中的代码以供进一步分析。 driver.findElement(By.xpath("//div[@class='RadComboBoxDropDown RadComboBoxDropDown_Silk'][contains(@id,'_cblUser_DropDown')]//ul[@class='rcbList']//label[contains(. ,'John, Smith')]/input[@class='rcbCheckBox']")).click();
【问题讨论】:
-
您尝试使用 Selenium 自动化哪个浏览器?什么是配置?除了单击复选框之外还有其他功能吗?
-
@CodeJockey - 它的 chrome 并展开下拉列表但不选择/单击复选框项目。下拉菜单展开和关闭。
-
也许尝试给每个复选框元素一个 ID。这样你只需要输入 Id,你就不必乱用这些过于复杂的选择器了。
标签: java selenium selenium-webdriver xpath webdriver