jsoup
jsoup copied to clipboard
cssSelector produces a different result to Chrome
@Test
void test()
{
final String html = """
<html>
<head>
<title>Funny ID</title>
</head>
<body>
<img src="/image.jpg" id="0% Platform Image" />
</body>
</html>""";
final Document document = Jsoup.parse(html);
final String jsoupSelector = document.getElementsByTag("img").get(0).cssSelector();
final String chromeSelector = "#\\30 \\%\\ Platform\\ Image";
assertEquals(chromeSelector, jsoupSelector);
}
The CSS selector jsoup generates is #0\%\ Platform\ Image, and the one Chrome generates is #\30 \%\ Platform\ Image. The jsoup-generated one won't find the node in Chrome Dev Tools
I'm not too sure how CSS selectors should work, but I thought I'd point out the discrepency vs. Chrome.