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

element.selectXpath unexpected behaviour. #1889

Closed
zaurkadiev opened this issue Jan 26, 2023 · 1 comment
Closed

element.selectXpath unexpected behaviour. #1889

zaurkadiev opened this issue Jan 26, 2023 · 1 comment
Labels
not-a-bug This issue is not a bug; it is working as per spec

Comments

@zaurkadiev
Copy link

zaurkadiev commented Jan 26, 2023

Example:

save

Let's assume we have same elements div1, div2, div3 with a similar inner tag structure.

If I have element div2 and try element.selectXpath(path), I have the result from div1. Similar with the element div3. If I have the element div3 and call element.selectXpath(path) I have the result from div1.

By the way element.select(selector) works just as expected, div1 selects only inside div1 scope, div1 inside div1 scope, etc.

Seems like this is an issue:

Inside mentioned test case.
https://github.com/jhy/jsoup/blame/be24647192f7870da500fb83650bacafed81151f/src/test/java/org/jsoup/select/XpathTest.java#L38

assertEquals(1, div.selectXpath("//body").size()); // the whole document is visible on the div context

Originally posted by @zaurkadiev in #1856 (comment)

@jhy
Copy link
Owner

jhy commented Jan 26, 2023

Rather than a picture and a narrative, your report would be a lot better with a simple repeatable test case showing what you're trying to do, what you're getting, and what you want instead. You haven't mentioned what XPath query you are using so I can't evaluate your issue.

However - by referencing the //body test case, my guess is that you are using absolute queries? The element.selectXpath() method uses the given element as the context, but the entire DOM is still available. If you provide a relative query, it will be relative to the context element, and if you provide an absolute query, it will be absolute to the entire DOM. Hence, the test case.

See #1652 for background on this.

LMK if with that understanding your issue is resolved, otherwise please provide a simple test case.

@jhy jhy added the needs-more-info More information is needed from the reporter to progress the issue label Jan 26, 2023
@jhy jhy added not-a-bug This issue is not a bug; it is working as per spec and removed needs-more-info More information is needed from the reporter to progress the issue labels Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-a-bug This issue is not a bug; it is working as per spec
Projects
None yet
Development

No branches or pull requests

2 participants