Fuzi icon indicating copy to clipboard operation
Fuzi copied to clipboard

CSS selector expression generates XPath error

Open dafi opened this issue 9 years ago • 2 comments

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()

dafi avatar Feb 07 '16 16:02 dafi

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.

cezheng avatar Feb 08 '16 09:02 cezheng

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-']

iDevPro avatar Jun 10 '19 05:06 iDevPro