Skip to content

feat: add elementIndex step option for targeting specific elements#5499

Open
DavertMik wants to merge 5 commits into4.xfrom
feat/element-position-select
Open

feat: add elementIndex step option for targeting specific elements#5499
DavertMik wants to merge 5 commits into4.xfrom
feat/element-position-select

Conversation

@DavertMik
Copy link
Copy Markdown
Contributor

Summary

  • Add elementIndex step option to select a specific element when multiple match a locator
  • Supports positive (1-based), negative (-1 = last), and 'first'/'last' aliases
  • When only one element matches, elementIndex is silently ignored
  • Overrides strict: true mode when set (user explicitly chose which element)
  • Implemented across Playwright, Puppeteer, and WebDriver helpers
  • Add documentation page for element selection and strict mode
import step from 'codeceptjs/steps'

I.click('a', step.opts({ elementIndex: 2 }))    // 2nd element
I.click('a', step.opts({ elementIndex: -1 }))   // last element
I.click('a', step.opts({ elementIndex: 'last' })) // same as -1

Test plan

  • All 7 new elementIndex tests pass for Playwright
  • All 7 new elementIndex tests pass for Puppeteer
  • Existing strict mode tests still pass (no regressions)
  • Existing click/fillField/selectOption/checkOption tests pass
  • Run WebDriver tests when Selenium available

🤖 Generated with Claude Code

When multiple elements match a locator, users can now specify which one
to interact with using step.opts({ elementIndex }). Supports positive
(1-based), negative (-1 = last), and 'first'/'last' aliases. Silently
ignored when only one element matches. Overrides strict mode when set.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DavertMik DavertMik changed the base branch from 3.x to 4.x March 29, 2026 18:30
DavertMik and others added 4 commits March 29, 2026 21:38
Add StepOptions typedef with elementIndex and ignoreCase in JSDoc.
Add declare module for 'codeceptjs/steps' for IDE autocompletion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
toAbsoluteXPath() now returns //html/... instead of /html/... to match
standard absolute XPath notation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
instanceof fails when StepConfig is loaded from different module paths
(e.g., symlinked packages). Add __isStepConfig marker and static
isStepConfig() method for reliable detection across module boundaries.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant