use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method mixCombinator.
@Test
public void mixCombinator() {
String h = "<div class=foo><ol><li>One<li>Two<li>Three</ol></div>";
Document doc = Jsoup.parse(h);
Elements sibs = doc.select("body > div.foo li + li");
assertEquals(2, sibs.size());
assertEquals("Two", sibs.get(0).text());
assertEquals("Three", sibs.get(1).text());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method deeperDescendant.
@Test
public void deeperDescendant() {
String h = "<div class=head><p><span class=first>Hello</div><div class=head><p class=first><span>Another</span><p>Again</div>";
Document doc = Jsoup.parse(h);
Element root = doc.getElementsByClass("head").first();
Elements els = root.select("div p .first");
assertEquals(1, els.size());
assertEquals("Hello", els.first().text());
assertEquals("span", els.first().tagName());
Elements aboveRoot = root.select("body p .first");
assertEquals(0, aboveRoot.size());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method notParas.
@Test
public void notParas() {
Document doc = Jsoup.parse("<p id=1>One</p> <p>Two</p> <p><span>Three</span></p>");
Elements el1 = doc.select("p:not([id=1])");
assertEquals(2, el1.size());
assertEquals("Two", el1.first().text());
assertEquals("Three", el1.last().text());
Elements el2 = doc.select("p:not(:has(span))");
assertEquals(2, el2.size());
assertEquals("One", el2.first().text());
assertEquals("Two", el2.last().text());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method containsWithQuote.
@Test
public void containsWithQuote() {
String html = "<p>One'One</p><p>One'Two</p>";
Document doc = Jsoup.parse(html);
Elements els = doc.select("p:contains(One\\'One)");
assertEquals(1, els.size());
assertEquals("One'One", els.text());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method testPseudoGreaterThan.
@Test
public void testPseudoGreaterThan() {
Document doc = Jsoup.parse("<div><p>One</p><p>Two</p><p>Three</p></div><div><p>Four</p>");
Elements ps = doc.select("div p:gt(0)");
assertEquals(2, ps.size());
assertEquals("Two", ps.get(0).text());
assertEquals("Three", ps.get(1).text());
}
Aggregations