Skip to content

cssSelector produces a different result to Chrome #1967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
samshutchins opened this issue Jun 8, 2023 · 1 comment
Closed

cssSelector produces a different result to Chrome #1967

samshutchins opened this issue Jun 8, 2023 · 1 comment
Labels
fixed An {bug|improvement} that has been {fixed|implemented}
Milestone

Comments

@samshutchins
Copy link

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

@jhy jhy self-assigned this Jul 8, 2024
@jhy jhy added this to the 1.18.1 milestone Jul 8, 2024
@jhy jhy removed their assignment Jul 8, 2024
@jhy jhy removed this from the 1.18.1 milestone Jul 8, 2024
@cketti
Copy link
Contributor

cketti commented Apr 24, 2025

This is fixed by #2297 + #2305.

@jhy jhy added the fixed An {bug|improvement} that has been {fixed|implemented} label Apr 24, 2025
@jhy jhy added this to the 1.20.1 milestone Apr 24, 2025
@jhy jhy closed this as completed Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed An {bug|improvement} that has been {fixed|implemented}
Projects
None yet
Development

No branches or pull requests

3 participants