Bugfix: nodes() only return the first element #113
parent
41c2ea9498
commit
3939074a23
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue