Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.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 使用HtmlUnit在DomNode上调用getByXPath_Java_Htmlunit - Fatal编程技术网

Java 使用HtmlUnit在DomNode上调用getByXPath

Java 使用HtmlUnit在DomNode上调用getByXPath,java,htmlunit,Java,Htmlunit,我已经使用getByXPath从HTMLPage对象中提取了DomNode对象列表。但是,当我再次尝试使用getByXPath查询返回的DomNode对象时,结果就像查询HTMLPage对象一样 final WebClient webClient = new WebClient(); HTMLPage page = (HtmlPage) webClient.getPage("http://test.page.com"); final List<HtmlTableCell> cell

我已经使用getByXPath从HTMLPage对象中提取了DomNode对象列表。但是,当我再次尝试使用getByXPath查询返回的DomNode对象时,结果就像查询HTMLPage对象一样

final WebClient webClient = new WebClient();
HTMLPage page = (HtmlPage) webClient.getPage("http://test.page.com");

final List<HtmlTableCell> cells = (List<HtmlTableCell>) page.getByXPath("//td[@width='85%']");

// Number of cells: 16
logger.debug("Number of cells: " + cells.size());

HtmlTableCell cell = cells.get(0);
final List<HtmlTableCell> childCells = (List<HtmlTableCell>) cell.getByXPath("//td[@width='85%']");

// Number of cells: 16
logger.debug("Number of cells: " + childCells.size());
final-WebClient-WebClient=new-WebClient();
HTMLPage=(HTMLPage)webClient.getPage(“http://test.page.com");
最终列表单元格=(List)page.getByXPath(“//td[@width='85%]”);
//单元格数量:16
logger.debug(“单元格数:+cells.size());
HtmlTableCell=cells.get(0);
最终列表childCells=(List)cell.getByXPath(//td[@width='85%']);
//单元格数量:16
debug(“单元格数:+childCells.size());

//td
在XPath中意味着选择所有td元素,不管它们在文档中的什么位置。请参见

您好,我有同样的问题,根据您提供的参考链接,我尝试使用。用于当前节点而不是/,但它导致了一个错误。那是正确的吗?如果在XPath之前没有使用任何表达式,会发生什么?