我正在接收一个ElementNotVisibleException,虽然我不确定为什么。当我查看日志中的屏幕截图时,元素清晰可见。
下面是HTML代码
<div id="xdo:parameters" class="xdoParameters">
<table class="fieldText parameters" summary="" cellspacing="0">
<tbody>
<tr>
<td class="left">
<div id="xdo:_paramsBrncd_div" style="width: 120px; display: inline; white-space: nowrap; font-size: 13px; zoom: 1; margin: 0px; padding: 0px; font-family: Tahoma, Verdana, Helvetica, sans-serif; font-weight: normal; color: rgb(0, 0, 0); cursor: pointer;">
<input type="text" id="xdo:xdo:_paramsBrncd_div_input" name="xdo:xdo:_paramsBrncd_div_input" readonly="readonly" onkeypress="var code = EventUtils.getKeyCode(event); if (code == 40 || code == 13) {document.getElementById(this.id).parentNode.onclick();} return true;" class="mchoicebox" style="width: 103px; padding: 2px 0px 1px;">
<span style="border-style: solid; border-color: rgb(172, 186, 207) rgb(0, 0, 0) rgb(0, 0, 0) rgb(183, 183, 178); border-width: 1px; margin: 1px 1px 1px 0px; background-image: url("/xmlpserver/resource/blafplus/menu/gradient_n.png"); background-position: center top; background-repeat: repeat; font-size: 12px; padding-top: 1px; padding-bottom: 1px;">
<span tabindex="-1" style="margin-left: -2px; margin-right: -2px; background-repeat: no-repeat; background-image: url("/xmlpserver/resource/blafplus/menu/dropdown_n.png"); background-position: center center; font-size: 12px; outline-width: 0px; padding-right: 14px; cursor: pointer;">
<span style="opacity: 0; zoom: 1;"> </span>
</span>
</span>
<select name="_paramsBrncd" id="xdo:_paramsBrncd" multiple="multiple" style="display: none;">
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
<option value="400">400</option>
<option value="500">500</option>
<option value="999">999</option>
</select>
</div>
</td>
<td class="left">...</td>
</tr>
</tbody>
</table>
</div>
这是我的代码
Wait Until Element is Visible (//div[@id="xdo:parameters"]//select)[1] 5s
Select From List By Value (//div[@id="xdo:parameters"]//select)[1] 100
Select From List By Value (//div[@id="xdo:parameters"]//select)[2] 150
Select From List By Value (//div[@id="xdo:parameters"]//select)[2] 151
Wait Until Element is Visible //button[.="Apply"]
Click Element //button[.="Apply"]
抛出这个错误Element '(//div[@id="xdo:parameters"]//select)[1]' not visible after 5 seconds.
为什么不直接在ID处选择元素而不是通过父div呢?. 根据页面结构的不同,有些元素可能会动态加载——尤其是下拉框。因此,在尝试从dom中获取元素时,它可能根本不在那里。尝试其他元素定位符
//select[@id='xdo:_paramsBrncd']
应该没问题。
使用id定位符本身就更好了
${YOUR_ELEMENT_LOCATOR} id:xdo:_paramsBrncd