Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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
Java xpath如何选择匹配的所有元素_Java_Selenium_Xpath_Css Selectors_Webdriver - Fatal编程技术网

Java xpath如何选择匹配的所有元素

Java xpath如何选择匹配的所有元素,java,selenium,xpath,css-selectors,webdriver,Java,Selenium,Xpath,Css Selectors,Webdriver,需要从图片上的所有元素中获取文本 我不知道为什么它只接受第一个元素的文本 这是我的Xpath: //ul[@class='holders-list ng-scope']//li//article//div//div[@class='price-different clearfix']//ul//li//strong 以下方法可能有效 使用driver.findElementsBy方法并将值存储在列表中,该列表将包含所有XPath 例如: 将web元素存储到列表中,并使用for-each循环对其

需要从图片上的所有元素中获取文本

我不知道为什么它只接受第一个元素的文本

这是我的Xpath:

//ul[@class='holders-list ng-scope']//li//article//div//div[@class='price-different clearfix']//ul//li//strong

以下方法可能有效

使用
driver.findElementsBy
方法并将值存储在列表中,该列表将包含所有XPath

例如: 将web元素存储到列表中,并使用for-each循环对其进行迭代

List<WebElement> valueList = driver.findElements(By.xpath("//ul[@class='holders-list ng-scope']//li//article//div//div[@class='price-different clearfix']//ul//li//strong"));

for(WebElement value:valueList){
    System.out.println(value.getText());
}
List valueList=driver.findElements(By.xpath(//ul[@class='holders-List ng scope']///li//article//div//div[@class='price-different-clearfix']//ul li//strong));
for(WebElement值:valueList){
System.out.println(value.getText());
}

尝试时发生了什么?您还应该发布Java代码和html。我们如何知道这些html元素与所有其他元素的区别?或者文本相对于可区分元素的位置。请共享您的html,以便我们可以帮助您。