use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method generalSiblings.
@Test
public void generalSiblings() {
String h = "<ol><li id=1>One<li id=2>Two<li id=3>Three</ol>";
Document doc = Jsoup.parse(h);
Elements els = doc.select("#1 ~ #3");
assertEquals(1, els.size());
assertEquals("Three", els.first().text());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method selectClassWithSpace.
@Test
public void selectClassWithSpace() {
final String html = "<div class=\"value\">class without space</div>\n" + "<div class=\"value \">class with space</div>";
Document doc = Jsoup.parse(html);
Elements found = doc.select("div[class=value ]");
assertEquals(2, found.size());
assertEquals("class without space", found.get(0).text());
assertEquals("class with space", found.get(1).text());
found = doc.select("div[class=\"value \"]");
assertEquals(2, found.size());
assertEquals("class without space", found.get(0).text());
assertEquals("class with space", found.get(1).text());
found = doc.select("div[class=\"value\\ \"]");
assertEquals(0, found.size());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method handlesCommasInSelector.
@Test
public void handlesCommasInSelector() {
Document doc = Jsoup.parse("<p name='1,2'>One</p><div>Two</div><ol><li>123</li><li>Text</li></ol>");
Elements ps = doc.select("[name=1,2]");
assertEquals(1, ps.size());
Elements containers = doc.select("div, li:matches([0-9,]+)");
assertEquals(2, containers.size());
assertEquals("div", containers.get(0).tagName());
assertEquals("li", containers.get(1).tagName());
assertEquals("123", containers.get(1).text());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method parentWithClassChild.
@Test
public void parentWithClassChild() {
String h = "<h1 class=foo><a href=1 /></h1><h1 class=foo><a href=2 class=bar /></h1><h1><a href=3 /></h1>";
Document doc = Jsoup.parse(h);
Elements allAs = doc.select("h1 > a");
assertEquals(3, allAs.size());
assertEquals("a", allAs.first().tagName());
Elements fooAs = doc.select("h1.foo > a");
assertEquals(2, fooAs.size());
assertEquals("a", fooAs.first().tagName());
Elements barAs = doc.select("h1.foo > a.bar");
assertEquals(1, barAs.size());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method testGroupOr.
@Test
public void testGroupOr() {
String h = "<div title=foo /><div title=bar /><div /><p></p><img /><span title=qux>";
Document doc = Jsoup.parse(h);
Elements els = doc.select("p,div,[title]");
assertEquals(5, els.size());
assertEquals("div", els.get(0).tagName());
assertEquals("foo", els.get(0).attr("title"));
assertEquals("div", els.get(1).tagName());
assertEquals("bar", els.get(1).attr("title"));
assertEquals("div", els.get(2).tagName());
// missing attributes come back as empty string
assertTrue(els.get(2).attr("title").length() == 0);
assertFalse(els.get(2).hasAttr("title"));
assertEquals("p", els.get(3).tagName());
assertEquals("span", els.get(4).tagName());
}
Aggregations