Skip to content

Commit 6f14a47

Browse files
DavertMikclaude
andcommitted
docs: add exact/strictMode per-step options to element selection guide
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6e4f7c5 commit 6f14a47

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

docs/element-selection.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,39 @@ When a test fails in strict mode, the error includes a `fetchDetails()` method t
8282
// Use a more specific locator or grabWebElements() to work with multiple elements
8383
```
8484

85-
When you do need to target one of multiple matches in strict mode, `elementIndex` overrides the check — no error is thrown because you've explicitly chosen which element to use:
85+
Strict mode is supported in **Playwright**, **Puppeteer**, and **WebDriver** helpers.
86+
87+
### Per-Step Strict Mode with `exact`
88+
89+
You don't have to enable strict mode globally. Use `exact: true` to enforce it on a single step — handy when most of your tests are fine with default behavior but a particular action needs to be precise:
90+
91+
```js
92+
import step from 'codeceptjs/steps'
93+
94+
I.click('a', step.opts({ exact: true }))
95+
// throws MultipleElementsFound if more than one link matches
96+
```
97+
98+
`strictMode: true` is an alias if you prefer a more descriptive name:
99+
100+
```js
101+
I.click('a', step.opts({ strictMode: true }))
102+
```
103+
104+
It works the other way too. If your helper has `strict: true` globally but you need to relax it for one step, use `exact: false`:
105+
106+
```js
107+
// strict: true in config, but this step allows multiple matches
108+
I.click('a', step.opts({ exact: false }))
109+
```
110+
111+
And when you know there are multiple matches and want a specific one, `elementIndex` also overrides the strict check — no error is thrown because you've explicitly chosen which element to use:
86112

87113
```js
88114
// strict: true in config, but this works without error
89115
I.click('a', step.opts({ elementIndex: 2 }))
90116
```
91117

92-
Strict mode is supported in **Playwright**, **Puppeteer**, and **WebDriver** helpers.
93-
94118
## Summary
95119

96120
| Situation | Approach |

0 commit comments

Comments
 (0)