![](/img/trans.png)
[英]Selenium Webdrive (Java) - find an element where attribute is disabled=“”
[英]Selenium Webdrive (Java) - find an element in xpath where is no specific attribute
我有以下声明:
String v_name = "Computer";
String v_test1 = new WebDriverWait(Login.driver,10).until(ExpectedConditions.visibilityOfElementLocated
(By.xpath("//span[.=\""+v_name+"\"]/following-sibling::span"))).getText();
我需要以某种方式获得没有style =“ display:none;”的值。
<div class="test">
<span>WIN-S38B7T042RC</span>
<span style="display: none;>CLOSED</span>
<span>OPENED</span>
<span style="display: none;>CLOSED</span>
</div>
我不能使用span [1]之类的选项。
因此,我想找到一些更灵活的选择。
像这样的东西: /following-sibling::span **not in** style="display: none;"
XPath非常灵活; 一种方式是这样的:
By.xpath("//span[not(contains(@style, 'display: none;'))]/")
甚至可能是这样的:
By.xpath("//span[not(@style)]/")
当然,您也可以使用类似于您尝试过的方法,例如
By.xpath("//span[/following-sibling::span/@style]/")
但这可能比必要的更为复杂。
请注意,这些都没有经过测试,但它们应该在理论上起作用。
我建议您使用此xpath,最简单,最简单
//span[not(contains(@style, 'display: none;'))]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.