I have the following statement:
String v_name = "Computer";
String v_test1 = new WebDriverWait(Login.driver,10).until(ExpectedConditions.visibilityOfElementLocated
(By.xpath("//span[.=\""+v_name+"\"]/following-sibling::span"))).getText();
I need to get somehow the value with no 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>
I can't use options like span[1].
So, I want to find some more flexible option.
Something like : /following-sibling::span **not in** style="display: none;"
XPath is quite flexible; one way would be something like this:
By.xpath("//span[not(contains(@style, 'display: none;'))]/")
or probably even something like this:
By.xpath("//span[not(@style)]/")
Of course you can also use something similar to what you tried, eg
By.xpath("//span[/following-sibling::span/@style]/")
But that's probably more complicated than necessary.
Mind you, none of these are tested but they should work in theory.
我建议您使用此xpath,最简单,最简单
//span[not(contains(@style, 'display: none;'))]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.