0

尝试使用 xPath 从 div 中获取文本。在浏览器中查找信息很好,但是当我尝试以一个想法运行时,我得到错误:“是:[对象文本]。它应该是一个元素。”

       List<WebElement> priceGameWebElement =  webDriver.findElements(By.xpath("//div[contains(@class,'search_price')]" +
            "/text()[normalize-space()][1]"));

我需要做什么才能使一切正常?

4

1 回答 1

1

您可以在这样的部分之前“中断”您的查询/text()...

List<WebElement> priceGameWebElement =  webDriver.findElements(By.xpath("//div[contains(@class,'search_price')]"));

然后你应该得到一个List<WebElement>包含text()节点的元素以便进一步区分。他们可能会被.getText()函数查询。

于 2021-10-01T00:11:41.013 回答