是否可以单击 div
元素下的 span
按钮,我也想使用输入的 id 来使我的测试稳定。
HTML:
<div class="idit-go">
<input id="IDITForm@checkRuleVO" class="GoLong align-left idit-go-text" type="text" value="" title="Validation Rule" tabindex="257" name="unknown" ignoredisableenableaction="true" helptextinfo="" disabled="">
<div class="idit-go-buttons">
<span id="IDITForm@checkRuleVOGoClearButtonClear" class="idit-go-clear" title="Clear" tabindex="259" onclick="clearField('IDITForm@checkRuleVOhidden');clearField('IDITForm@checkRuleVO');;">
<span class="fa-stack idit-go-button" value="" title="" tabindex="258" onclick="newPerformSubAction('selectRule',true);">
<i class="fa fa-stack-1x fa-square"></i>
<i class="fa fa-stack-1x fa-ellipsis-h"></i>
</span>
</div>
它在屏幕上的外观:
正如您所看到的,右侧的 3 个点按钮就是我要单击的按钮。提前致谢。
最佳答案
在这种情况下,您可以识别具有 id
属性的 span
,然后只需使用 following-sibling
(从您的示例来看,它们似乎处于同一水平)。
driver.findElement(By.xpath(".//[@id='IDITForm@checkRuleVOGoClearButtonClear']/following-sibling::span"));
关于java - 通过父级的 id(带有 id)单击 span 按钮 - selenium with java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39019849/