Repository navigation
feat(locator): add first() and last() narrowing methods (#132) - #143
Merged
shossain786 merged 1 commit intoOct 10, 2026
Merged
Conversation
Contributor
|
Merged — thanks @PUSHPAK-JAISWAL. Resolving |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Adds
first()andlast()narrowing methods toLocatoras thin, readable wrappers:first()narrows matched elements to the first item (equivalent tonth(0)).last()narrows matched elements to the last item.Previously,
Locatorsupportednth(int)but lacked dedicatedfirst()andlast()convenience methods for the most common narrowing calls (e.g.,getByRole(Role.LISTITEM).first()).last()resolves lazily at action time insideresolveAll()on every poll rather than fixing an index at build time. This ensures that dynamic DOM updates, element list growth, and the framework's auto-wait contract (#67 / #68) work correctly: candidates are re-queried from scratch on every poll and retried untiltimeouts.explicit.Closes #132
Type of change
Checklist
mvn clean verify)@SeleniumBootApipublic APIs (or a major version bump is justified below)docs-site/)Notes for reviewers
last()stores no element references or indices at build time. When a terminal action (click(),getText(),element(), etc.) runs,candidates.get(candidates.size() - 1)is evaluated at poll time.resolveAll()throwsLocatorException, which is caught by the retry loop and polled until elements appear or explicit timeout elapses. If an element goes stale between check and action, it re-resolves and picks the fresh element.first(),last(), ornth(index)cleanly clears previous index-narrowing flags on the locator instance.Locator.java.docs-site/docs/guides/semantic-locators.md.docs-site/docs/changelog.mdandCHANGELOG.md.LocatorTestandLocatorStaleElementTestpass, and the full 587-test suite passes with 0 failures.