Skip to content
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

CSS selector expression generates XPath error #8

Open
dafi opened this issue Feb 7, 2016 · 2 comments
Open

CSS selector expression generates XPath error #8

dafi opened this issue Feb 7, 2016 · 2 comments

Comments

@dafi
Copy link

dafi commented Feb 7, 2016

I heavly use css selectors and when they are a bit more complex the XPathFromCSS routine fails

The css selector .box-paging a:not(.active) generates the error

XPath error : Undefined namespace prefix
.//*[contains(concat(' ',normalize-space(@class),' '),' box-paging ')]/descendant::a:not([contains(concat(' ',normalize-space(@class),' '),' active) ')]

You can reproduce the error yourself using the following snippet

    func checkSelector() {
        let html = "<div class=\"box-paging\"><a class=\"active\" href=\"1.html\">1</a><a href=\"2.html\">2</a><a href=\"3.html\">3</a></div>"

        if let htmlDocument = try? HTMLDocument(string: html) {
            htmlDocument.css(".box-paging a:not(.active)")
        }

    }

Obviously the selector works fine using firebug or document.querySelectorAll()

@cezheng
Copy link
Owner

cezheng commented Feb 8, 2016

Hi, thanks for reporting this issue. I guess many CSS3 selectors are still not supported in Fuzi at the moment, but I'm planning to add them soon. Currently I'm on a vacation without a Mac at hand, so maybe when I have some free time after I get back.

@iDevPro
Copy link

iDevPro commented Jun 10, 2019

Hello, thanks for fast library, but I have same issue:

  • I was install latest version from git and check css regex query, it's still crash :(
root.xpath("//*[@id = 'booklist']//*[starts-with(@id, 'div-userbook-')]") // work
root.css("#booklist > div[id^='div-userbook-']") // crashed on xpath conversion rules
// XPath error : Invalid expression
// .//*[@id = 'booklist']/div[@id^='div-userbook-']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants