Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.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 Webdriver自动化-无法使用xpath找到元素(在Octane2.0基准页面中)_Java_Selenium_Xpath_Automation_Webdriver - Fatal编程技术网

Java Webdriver自动化-无法使用xpath找到元素(在Octane2.0基准页面中)

Java Webdriver自动化-无法使用xpath找到元素(在Octane2.0基准页面中),java,selenium,xpath,automation,webdriver,Java,Selenium,Xpath,Automation,Webdriver,我正试图用WebElements解析Octane基准页面: <div class="hero-unit" id="inside-anchor"> <h1 id="main-banner" align="center">Start Octane 2.0</h1> <div id="bar-appendix"></div> </div> 我已经用辛烷值页初始化了驱动程序: driver.get("http://

我正试图用WebElements解析Octane基准页面:

<div class="hero-unit" id="inside-anchor">
    <h1 id="main-banner" align="center">Start Octane 2.0</h1>
    <div id="bar-appendix"></div>
</div>
我已经用辛烷值页初始化了驱动程序:

driver.get("http://octane-benchmark.googlecode.com/svn/latest/index.html");
我正在尝试用xpath解析它:

String xpathString = "//div[@class='hero-unit']//h1";   
String line = driver.findElement(By.xpath(xpathString)).getText();
System.out.println(line);
但是Java返回空指针异常(在线)-函数FindElement()在此.html页面上找不到任何内容

驱动程序启动良好,它为getCurrentUrl()函数返回适当的值,但不能返回PageSource(),也不能为findElement(By.something…)返回任何值。 看起来,这个辛烷值页面有停止每个搜索请求的功能(在解析过程中)。以同样的方式,我已经解析了其他7个基准页面,它们工作得很好,但是这个辛烷值页面…对于WebDriver来说,它就像是“空的”

我不知道是因为什么

<script type="text/javascript"> 

还是别的什么

这个辛烷值基准页面有什么特别之处吗

谢谢…

只有当html页面符合XML标准时,
By.xpath()
才有效。可能Octane 2.0页面不符合要求,因此该方法返回null。

xPath()适用于符合XML标准的站点。HTML更为宽容;您可能会丢失结束标记和其他错误,但在XML中这是禁止的。因此,html可能不符合XML标准,因此我通过验证您在该站点的链接进行了双重检查:

你猜怎么着?它有一些错误。您可以通过首先在此站点上进行验证来避免下次的麻烦。当然,这并不意味着符合XML的站点都适合xPath()webscraping(隐藏元素、javascript等)。但是,从报告的错误的性质,您可能可以判断哪些错误不是

<script type="text/javascript">