Bugfix: nodes() only return the first element #113

master
yihua.huang 2014-05-27 17:53:06 +08:00
parent 41c2ea9498
commit 3939074a23
2 changed files with 15 additions and 2 deletions

View File

@ -81,8 +81,12 @@ public class HtmlNode extends AbstractSelectable {
@Override
public List<Selectable> nodes() {
ArrayList<Selectable> selectables = new ArrayList<Selectable>();
selectables.add(this);
List<Selectable> selectables = new ArrayList<Selectable>();
for (Element element : getElements()) {
List<Element> childElements = new ArrayList<Element>(1);
childElements.add(element);
selectables.add(new HtmlNode(childElements));
}
return selectables;
}

View File

@ -23,4 +23,13 @@ public class SelectorTest {
assertThat(linksWithoutChain).hasSameSizeAs(linksWithChainFirstCall);
assertThat(linksWithChainFirstCall).hasSameSizeAs(linksWithChainSecondCall);
}
@Test
public void testNodes() throws Exception {
Html selectable = new Html(html);
List<Selectable> links = selectable.xpath("//a").nodes();
for (Selectable link : links) {
System.out.println(link.xpath("/@href"));
}
}
}