jsoup icon indicating copy to clipboard operation
jsoup copied to clipboard

cssSelector produces a different result to Chrome

Open samshutchins opened this issue 2 years ago • 0 comments

    @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.

samshutchins avatar Jun 08 '23 13:06 samshutchins