我尝试使用相邻同级从下拉列表中选择值,但不起作用
这是 HTML:
<div id="dependsOnQuestionDiv"><div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen197" style="width: 17px;"><input type="text" size="24" autocomplete="off" id="dependsOnQuestion" name="dependsOnQuestion" class="x-form-text x-form-field x-trigger-noedit" readonly="" title="" style="width: 345px;"><img src="/mco/extjs/resources/images/default/s.gif" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen198"></div></div>
我尝试过以下方法:
(xpath =
"//input[@id='dependsOnQuestion']/following-sibling::img[@id='ext-gen198']"
和
> css = #dependsOnQuestion ~img "
但它点击了其他具有图像标签的元素
这是另一个图像标签 HTML,当我尝试单击下拉菜单时,它会被点击
<td class="x-grid3-col x-grid3-cell x-grid3-td-edit x-action-col-cell" style="width: 41px;" tabindex="0"><div class="x-grid3-cell-inner x-grid3-col-edit x-unselectable" unselectable="on"><img alt="" src="/mco/images/edit-button.png" class="x-action-col-icon x-action-col-0 "></div></td>
<div class="x-grid3-cell-inner x-grid3-col-edit x-unselectable" unselectable="on" xpath="1"><img alt="" src="/mco/images/edit-button.png" class="x-action-col-icon x-action-col-0 " style=""></div>
有人可以帮助我吗?
最佳答案
尝试下面的XPATH
选项。
xpath = "//img[@id='ext-gen198']/preceding-sibling::input[@id='dependsOnQuestion']"
或者
xpath = "//img[@id='ext-gen198']/preceding-sibling::input[1]"
关于java - 如何通过Java使用Selenium点击元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59680733/