我试图断言我们页面上的一个按钮被禁用了。下面的 HTML 是我目前正在使用的:
<div data-persona-noeditable="" style="display: block;">
<div class="c-potential-tooltip persona-name pull-left" data-potential-tooltip="">
<div data-name-persona="" class="marg5" data-original-title="" title="">autoTestMapped</div>
</div>
<button class="btn btn-small pull-left marg5" data-copy-persona="">Copy</button>
<button class="btn btn-small pull-left marg5" data-edit-persona="" style="display: inline-block;">Edit</button>
<button class="btn btn-small pull-left marg5" data-persona-deactivate="" disabled="" style="display: inline-block;">Deactivate</button>
<button class="btn btn-small pull-left marg5" data-persona-activate="" style="display: none;">Activate</button>
<i class="fa fa-times pull-down" data-persona-delete="" style="display: none;"></i>
</div>
我正在尝试检查 Deactivate 按钮是否被禁用,但我想将它与行中的标签名称绑定(bind)在一起,autoTestMapped
。
它嵌套在第一个 div 中,我无法弄清楚如何让 Selenium 查看它们以确认按钮与该特定用户相关。
我尝试了不同的变体:
Assert.assertFalse("deactivate button is disabled for autoTestMapped", driver.findElement(By.xpath("//*div[contains(text(), 'autoTestMapped')]")).isEnabled());
包括使用 |连接两个单独的 XPath,但似乎没有任何效果。我可以对 xpath 位置进行硬编码,但这不是静态的,因为新创建的用户可能会导致列表向上或向下移动。
如有任何帮助,我们将不胜感激。
最佳答案
following-sibling
在这里会有帮助:
//div[contains(@class, "persona-name") and div = "autoTestMapped"]/following-sibling::button[. = "Deactivate"]
关于java - 如何为 Selenium webdriver assert 连接嵌套的 xpath?即连续标签和单独的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30734691/