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

pull/130/head
yihua.huang 11 years ago
parent 41c2ea9498
commit 3939074a23

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

@ -23,4 +23,13 @@ public class SelectorTest {
assertThat(linksWithoutChain).hasSameSizeAs(linksWithChainFirstCall); assertThat(linksWithoutChain).hasSameSizeAs(linksWithChainFirstCall);
assertThat(linksWithChainFirstCall).hasSameSizeAs(linksWithChainSecondCall); 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"));
}
}
} }

Loading…
Cancel
Save