我正在尝试使用JavascriptExecutor document.evaluate从html获取div的第一个node
String txt = ((JavascriptExecutor)driver)
.executeScript("return document.evaluate(\"//div[@id = 'SIvCob']/node()[1]\",
document, null, XPathResult.ANY_TYPE, null)").toString();
System.out.print(txt);但是我在executeScript得到了一个错误
org.openqa.selenium.JavascriptException:
javascript error:
Failed to read the 'numberValue' property from 'XPathResult':
The result type is not a number.我想要的node是一个简单的文本(没有html标签或其他东西)
我使用的是ChromeDriver。
发布于 2021-06-10 19:49:59
我的问题的解决方案是在document.evaluate(...)的结果中调用stringValue。
像这样:document.evaluate(...).stringValue
https://stackoverflow.com/questions/55164684
复制相似问题