Ejemplo n.º 1
0
  @Test
  public void testTwoHtml() throws IOException {
    File file = new File(testDataRoot, "two.html");
    String htmlContent = FileUtil.readString(file);

    Document document = new LagartoDOMBuilder().parse(htmlContent);

    Node html = new NodeSelector(document).select("html").get(0);
    assertNotNull(html);

    Node body = new NodeSelector(html).selectFirst("body");
    Element h1 = body.getFirstChildElement();
    assertEquals("h1", h1.getNodeName());

    Node comment1 = body.getFirstChild().getNextSibling();
    assertEquals(Node.NodeType.COMMENT, comment1.getNodeType());

    Element p = (Element) new NodeSelector(body).selectFirst("p");

    assertEquals(h1, p.getPreviousSiblingElement());
    assertEquals(h1, comment1.getNextSiblingElement());
    assertNull(comment1.getNextSiblingName());

    // check if filter works just for sub elements
    List<Node> p_ems = new NodeSelector(p).select("em");
    assertEquals(1, p_ems.size());

    Element script = (Element) new NodeSelector(html).selectFirst("script");
    assertEquals("text/javascript", script.getAttribute("type"));

    assertTrue(document.check());
  }
Ejemplo n.º 2
0
  @Test
  public void testGroupOfSelectors() throws IOException {
    File file = new File(testDataRoot, "one.html");
    String htmlContent = FileUtil.readString(file);

    Document document = new LagartoDOMBuilder().parse(htmlContent);

    List<Node> nodes = new NodeSelector(document).select("em, b, b");
    assertEquals(9, nodes.size());

    assertTrue(document.check());
  }