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

Find method not able to specify starting find from 1 level below #189

Open
HongyiFu opened this issue Aug 10, 2023 · 1 comment
Open

Find method not able to specify starting find from 1 level below #189

HongyiFu opened this issue Aug 10, 2023 · 1 comment

Comments

@HongyiFu
Copy link

HongyiFu commented Aug 10, 2023

Expected behavior and actual behavior:

In jQuery, you can do $el.find("> div") to match only div elements 1 level below current. Following from this, if we write $el.find("> div > p"), we can match <p> elements that are grandchildren of the current element.

This doesn't seem possible with jOOX, as this stacktrace is produced.

Exception in thread "main" org.joox.selector.ScannerException: Bad input!
    at org.joox.selector.Scanner.scan (Scanner.java:1889)
    at org.joox.selector CSS2XPath.css2xpath (CSS2XPath.java:51)
    at org.joox.Impl.find (Impl.java:488)
    at org.joox.Impl.find (Impl.java:81)

Are there any alternatives to do this other than chaining children method $el.children('div').children('p')?

Steps to reproduce the problem:

As above $el.find("> div > p")

Versions:

  • jOOX: 2.0.0
  • Java: 17
@lukaseder
Copy link
Member

Thanks for your suggestion. That would be an interestnig improvement to the CSS2XPath utility:
https://github.com/jOOQ/jOOX/blob/main/jOOX/src/main/java/org/joox/selector/CSS2XPath.java

If you have some time, why not give it a shot? I'll be happy to review your PR.

Alternatively, note that the CSS selector support is just convenience. You can always just use Match::xpath instead, i.e. `$el.xpath("./div/p"). Usually, you'll get farther with XPath than with CSS selectors.

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

2 participants