-
Notifications
You must be signed in to change notification settings - Fork 23
fix: apply index after Java-side filtering in ElementQuery (#2033) #2035
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
base: main
Are you sure you want to change the base?
Conversation
When using ElementQuery with conditions like withPropertyValue(), calling first() or get(index) would fail if the element at that DOM position didn't match the condition. This happened because the JavaScript [index] was applied before Java-side condition filtering, so it would extract the wrong element and then filter it out. Fixed by: - Modified get(int index) to check if conditions exist - When conditions exist, fetch all elements and apply index after filtering - When no conditions exist, use the optimized JavaScript [index] path Added integration tests to verify withPropertyValue().first() and withPropertyValue().get(0) work correctly. Fixes #2033
|
Fixes #2033. |
|
Needs formatting + some tests are failing |
|
formatted and merged main, let's see if tests still fail |
Test Results 134 files - 33 134 suites - 33 57s ⏱️ - 1h 3m 44s For more details on these failures, see this check. Results for commit 5c5fcde. ± Comparison against base commit d623dc1. This pull request removes 169 tests.♻️ This comment has been updated with latest results. |
When ElementQuery uses Java-side conditions (like withLabel, withText, withPropertyValue, etc.), the JavaScript query must return ALL matching elements so that Java can apply the predicates for filtering. The tests were incorrectly expecting the script to end with ";return result[0]" for all .first() calls. For queries with conditions, the script correctly ends with ";return result" (all elements), and then Java applies filtering and indexing. Fixed by updating test helper methods findFirstConditionInElement() and findFirstConditionInDocument() to expect SINGLE_RESULT_QUERY_SUFFIX instead of FIRST_RESULT_QUERY_SUFFIX. This fixes 20 failing tests in ElementQueryTest related to condition-based queries. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Fixes #2033