Example #1
0
  @Test
  public void testGetElementsWithAttribute() {
    Document doc = Jsoup.parse("<div style='bold'><p title=qux><p><b style></b></p></div>");
    List<Element> els = doc.getElementsByAttribute("style");
    assertEquals(2, els.size());
    assertEquals("div", els.get(0).tagName());
    assertEquals("b", els.get(1).tagName());

    List<Element> none = doc.getElementsByAttribute("class");
    assertEquals(0, none.size());
  }
Example #2
0
  @Test
  public void testClassDomMethods() {
    Document doc =
        Jsoup.parse("<div><span class=' mellow yellow '>Hello <b>Yellow</b></span></div>");
    List<Element> els = doc.getElementsByAttribute("class");
    Element span = els.get(0);
    assertEquals("mellow yellow", span.className());
    assertTrue(span.hasClass("mellow"));
    assertTrue(span.hasClass("yellow"));
    Set<String> classes = span.classNames();
    assertEquals(2, classes.size());
    assertTrue(classes.contains("mellow"));
    assertTrue(classes.contains("yellow"));

    assertEquals("", doc.className());
    classes = doc.classNames();
    assertEquals(0, classes.size());
    assertFalse(doc.hasClass("mellow"));
  }