Commit 3939074a authored by yihua.huang's avatar yihua.huang

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

parent 41c2ea94
...@@ -81,8 +81,12 @@ public class HtmlNode extends AbstractSelectable { ...@@ -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 { ...@@ -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"));
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment