Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SeleniumWebDrive(Java)-在xpath中查找没有特定属性的元素_Java_Selenium - Fatal编程技术网

SeleniumWebDrive(Java)-在xpath中查找没有特定属性的元素

SeleniumWebDrive(Java)-在xpath中查找没有特定属性的元素,java,selenium,Java,Selenium,我有以下声明: 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=“dis

我有以下声明:

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;”的情况下以某种方式获取值


WIN-S38B7T042RC
关闭
我不能使用像span[1]这样的选项

所以,我想找到一些更灵活的选择


类似于:
/following sibling::span**notin**style=“display:none;”“

XPath非常灵活;一种方法是这样的:

By.xpath("//span[not(contains(@style, 'display: none;'))]/")
By.xpath("//span[not(@style)]/")
甚至可能是这样的:

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;'))]

谢谢,我检查了其中一个,它是为我查找的://span[.=”+v_name+“”]/以下兄弟姐妹::span[not(contains(@style,'display:none;'))]函数xpath text()无法与selenium一起使用。异常是否会通过某种方式使其不使用CSSSELECTOR?我认为cssselector在这种情况下会起作用faster@NguyenVuHoang谢谢,我不知道Selenium不支持
text()
(尽管我相信这可能取决于使用的XPath引擎,因为Selenium可以使用多个)。我已经相应地更改了答案。对于cssselector,您可以使用span:not([style])我同意,我正在使用它://span[.=“”+v_name+“”]/以下同级::span[not(contains(@style,'display:none;'))]