".class" selector seems to be failing
See original GitHub issueA more detailed post: http://stackoverflow.com/questions/42322374/jsoup-basic-class-css-selectors-not-working-html-shows-elements-exist-an
The problem can be summarized like so:
Debugging code:
Elements as = doc.select("a");
for (Element e : as) {
if (e.classNames().size() > 0)
M.debug(e.classNames());
if(e.classNames().contains("bigChar")) {
M.debug("found!");
}
}
as = doc.select(".bigChar");
M.debug("now: " + as);
for (Element e : as) {
if (e.classNames().size() > 0)
M.debug(e.classNames());
}
Output:
[logo]
[bigChar]
found!
[dotUnder]
[dotUnder]
[dotUnder]
[dotUnder]
[dotUnder]
now:
I’ve spent a while debugging this and I think the problem may have to do with malformed HTML. Attached is a sample input, and below is some simple code to run it (I am able to reproduce this problem consistently by reading from the file):
try {
Document doc = Jsoup.parse(new File("blahblah.txt"), "UTF-8");
System.out.println(doc.html());
System.out.println("FINAL");
System.out.println(doc.select(".bigChar"));
System.exit(0);
} catch (IOException e) {
e.printStackTrace();
}
You can see in the HTML output that the “bigChar” class is used, but the .bigChar selector doesn’t seem to find it.
In my run of the above code, my output is
</div>
<script type="text/javascript">
$('#footer').css('top', $(document).height() - $('#containerRoot').height());
</script>
</body>
</html>
FINAL
(i.e. nothing found for .bigChar)
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Jquery Class Selector Fails to Select new Class Instances ...
I'm semi-new to Javascript/jQuery so apologies in advanced if I'm missing something basic. I have a function that is triggered whenever a user...
Read more >Problems with the New Class Selector - Forum | Webflow
Renaming a global class is destructive and will break in all cases as the warning in the style manager indicates.
Read more >Class selectors - CSS: Cascading Style Sheets | MDN
The CSS class selector matches elements based on the contents of their class attribute.
Read more >Step 52 . I added the dessert selector but seem to fail
Tell us what's happening: Describe your issue in detail here. **Your code so far** /* file: index.html */ <!DOCTYPE html> <html lang="en"> ...
Read more >Little CSS Stuff Newcomers Get Confused About
The first one will select any element with that class name. ... It seems like as far as CSS is concerned, using classes...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Actually this is the same as #814 as @cketti pointed out 😃 I just forgot that try.jsoup wasn’t on 1.10.3.
Thanks for the report and the sleuthing.
The problem is that the attribute name is now all lower case, and something’s bugged in the case insensitivity of the attribute name.
You can see an e.g. here: http://try.jsoup.org/~l4ZA3QJ3p5WzWTD5y6v-tGu1Sh8 - change “Class” to “class” and it works. Will fix it up.