use of org.jsoup.select.Elements in project jsoup by jhy.
the class ParseTest method testSmhBizArticle.
@Test
public void testSmhBizArticle() throws IOException {
File in = getFile("/htmltests/smh-biz-article-1.html");
Document doc = Jsoup.parse(in, "UTF-8", "http://www.smh.com.au/business/the-boards-next-fear-the-female-quota-20100106-lteq.html");
assertEquals("The board’s next fear: the female quota", // note that the apos in the source is a literal ’ (8217), not escaped or '
doc.title());
assertEquals("en", doc.select("html").attr("xml:lang"));
Elements articleBody = doc.select(".articleBody > *");
assertEquals(17, articleBody.size());
// todo: more tests!
}
use of org.jsoup.select.Elements in project jsoup by jhy.
the class AttributeParseTest method strictAttributeUnescapes.
@Test
public void strictAttributeUnescapes() {
String html = "<a id=1 href='?foo=bar&mid<=true'>One</a> <a id=2 href='?foo=bar<qux&lg=1'>Two</a>";
Elements els = Jsoup.parse(html).select("a");
assertEquals("?foo=bar&mid<=true", els.first().attr("href"));
assertEquals("?foo=bar<qux&lg=1", els.last().attr("href"));
}
use of org.jsoup.select.Elements in project jsoup by jhy.
the class ElementTest method testPrependNewHtml.
@Test
public void testPrependNewHtml() {
Document doc = Jsoup.parse("<div id=1><p>Hello</p></div>");
Element div = doc.getElementById("1");
div.prepend("<p>there</p><p>now</p>");
assertEquals("<p>there</p><p>now</p><p>Hello</p>", TextUtil.stripNewlines(div.html()));
// check sibling index (reindexChildren):
Elements ps = doc.select("p");
for (int i = 0; i < ps.size(); i++) {
assertEquals(i, ps.get(i).siblingIndex);
}
}
use of org.jsoup.select.Elements in project jsoup by jhy.
the class ElementTest method insertChildrenAtPosition.
@Test
public void insertChildrenAtPosition() {
Document doc = Jsoup.parse("<div id=1>Text1 <p>One</p> Text2 <p>Two</p></div><div id=2>Text3 <p>Three</p></div>");
Element div1 = doc.select("div").get(0);
Elements p1s = div1.select("p");
Element div2 = doc.select("div").get(1);
assertEquals(2, div2.childNodeSize());
div2.insertChildren(-1, p1s);
// moved two out
assertEquals(2, div1.childNodeSize());
assertEquals(4, div2.childNodeSize());
// should be last
assertEquals(3, p1s.get(1).siblingIndex());
List<Node> els = new ArrayList<Node>();
Element el1 = new Element(Tag.valueOf("span"), "").text("Span1");
Element el2 = new Element(Tag.valueOf("span"), "").text("Span2");
TextNode tn1 = new TextNode("Text4", "");
els.add(el1);
els.add(el2);
els.add(tn1);
assertNull(el1.parent());
div2.insertChildren(-2, els);
assertEquals(div2, el1.parent());
assertEquals(7, div2.childNodeSize());
assertEquals(3, el1.siblingIndex());
assertEquals(4, el2.siblingIndex());
assertEquals(5, tn1.siblingIndex());
}
use of org.jsoup.select.Elements in project jsoup by jhy.
the class ElementTest method testHasText.
@Test
public void testHasText() {
Document doc = Jsoup.parse("<div><p>Hello</p><p></p></div>");
Element div = doc.select("div").first();
Elements ps = doc.select("p");
assertTrue(div.hasText());
assertTrue(ps.first().hasText());
assertFalse(ps.last().hasText());
}
Aggregations