You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/element-selection.md
+27-3Lines changed: 27 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,15 +82,39 @@ When a test fails in strict mode, the error includes a `fetchDetails()` method t
82
82
// Use a more specific locator or grabWebElements() to work with multiple elements
83
83
```
84
84
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
+
importstepfrom'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:
86
112
87
113
```js
88
114
// strict: true in config, but this works without error
89
115
I.click('a', step.opts({ elementIndex:2 }))
90
116
```
91
117
92
-
Strict mode is supported in **Playwright**, **Puppeteer**, and **WebDriver** helpers.
0 commit comments