use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method testCombinedWithContains.
@Test
public void testCombinedWithContains() {
Document doc = Jsoup.parse("<p id=1>One</p><p>Two +</p><p>Three +</p>");
Elements els = doc.select("p#1 + :contains(+)");
assertEquals(1, els.size());
assertEquals("Two +", els.text());
assertEquals("p", els.first().tagName());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method adjacentSiblingsWithId.
@Test
public void adjacentSiblingsWithId() {
String h = "<ol><li id=1>One<li id=2>Two<li id=3>Three</ol>";
Document doc = Jsoup.parse(h);
Elements sibs = doc.select("li#1 + li#2");
assertEquals(1, sibs.size());
assertEquals("Two", sibs.get(0).text());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method testPseudoContains.
@Test
public void testPseudoContains() {
Document doc = Jsoup.parse("<div><p>The Rain.</p> <p class=light>The <i>rain</i>.</p> <p>Rain, the.</p></div>");
Elements ps1 = doc.select("p:contains(Rain)");
assertEquals(3, ps1.size());
Elements ps2 = doc.select("p:contains(the rain)");
assertEquals(2, ps2.size());
assertEquals("The Rain.", ps2.first().html());
assertEquals("The <i>rain</i>.", ps2.last().html());
Elements ps3 = doc.select("p:contains(the Rain):has(i)");
assertEquals(1, ps3.size());
assertEquals("light", ps3.first().className());
Elements ps4 = doc.select(".light:contains(rain)");
assertEquals(1, ps4.size());
assertEquals("light", ps3.first().className());
Elements ps5 = doc.select(":contains(rain)");
// html, body, div,...
assertEquals(8, ps5.size());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method multiChildDescent.
@Test
public void multiChildDescent() {
String h = "<div id=foo><h1 class=bar><a href=http://example.com/>One</a></h1></div>";
Document doc = Jsoup.parse(h);
Elements els = doc.select("div#foo > h1.bar > a[href*=example]");
assertEquals(1, els.size());
assertEquals("a", els.first().tagName());
}
use of org.jsoup.nodes.Document in project jsoup by jhy.
the class SelectorTest method testPseudoEquals.
@Test
public void testPseudoEquals() {
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:eq(0)");
assertEquals(2, ps.size());
assertEquals("One", ps.get(0).text());
assertEquals("Four", ps.get(1).text());
Elements ps2 = doc.select("div:eq(0) p:eq(0)");
assertEquals(1, ps2.size());
assertEquals("One", ps2.get(0).text());
assertEquals("p", ps2.get(0).tagName());
}
Aggregations