java - 通过父级的 id(带有 id)单击 span 按钮 - selenium with java

标签 java html selenium xpath

是否可以单击 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>

它在屏幕上的外观:

demo

正如您所看到的,右侧的 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/

相关文章:

java - 将自签名证书换成受信任的证书?

html - 如何在没有 Javascript 的情况下制作带有下拉菜单的 CSS 选项卡?

html - 使用 <audio> 标签尝试在 Firefox 上流式传输 m3u8 时出现问题

node.js - Selenium-webdriver 无法在 NodeJS 中从 Mocha 打开 Firefox

selenium - WebDriver:如何自动输入屏蔽生日(//)字段

java - Maven springsource 仓库

java - 为什么这些 Java 类名必须在 Clojure 中完全限定?

java - 使用 byte-buddy 进行 Java 级别的仪器

html - Twitter Bootstrap 3 粘性页脚

java - 选择方法解释