In JSoup 1.7.1 this code passes, but in 1.8.3 it fails.
Last active
August 29, 2015 14:28
-
-
Save saibotsivad/946916e2ce8bf30490ae to your computer and use it in GitHub Desktop.
JSoup 1.7.1 to 1.8.3 inconsistency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.saibotsivad.parser; | |
import org.jsoup.Jsoup; | |
import org.jsoup.nodes.Document; | |
import org.jsoup.nodes.Element; | |
import org.jsoup.select.Elements; | |
import org.junit.Test; | |
import junit.framework.Assert; | |
public class PokingAtJsoup { | |
@Test | |
public void findInTable() { | |
String html = "<!DOCTYPE html>\n" + | |
"<html>\n" + | |
"\t<body>\n" + | |
"\t\t<table>\n" + | |
"\t\t\t<tbody>\n" + | |
"\t\t\t\t<tr>\n" + | |
"\t\t\t\t\t<td>\n" + | |
"\t\t\t\t\t\t<span>word</span>\n" + | |
"\t\t\t\t\t</td>\n" + | |
"\t\t\t\t</tr>\n" + | |
"\t\t\t</tbody>\n" + | |
"\t\t</table>\n" + | |
"\t\t<table>\n" + | |
"\t\t\t<tbody>\n" + | |
"\t\t\t\t<tr>\n" + | |
"\t\t\t\t\t<td>\n" + | |
"\t\t\t\t\t\t<span>word</span>\n" + | |
"\t\t\t\t\t</td>\n" + | |
"\t\t\t\t</tr>\n" + | |
"\t\t\t</tbody>\n" + | |
"\t\t</table>\n" + | |
"\t</body>\n" + | |
"</html>"; | |
Document document = Jsoup.parse(html); | |
Elements elements = document.select("table"); | |
int elementsFoundUsingSelect = elements.select("table:contains(word)").size(); | |
int elementsFoundUsingLoop = 0; | |
for (Element element : elements) { | |
if (element.select("table:contains(word)").size() > 0) { | |
elementsFoundUsingLoop++; | |
} | |
} | |
Assert.assertEquals("should find two but in 1.8.3 finds only one", 2, elementsFoundUsingLoop); | |
Assert.assertEquals("should find two", 2, elementsFoundUsingSelect); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment