[ Bug]: A stale ElementArray `$$()` iteration throws `Index out of bounds! $$(h1) returned only 0 elements.`
Author: dprevost-LMICreated Aug 31, 2026Updated Sep 13, 2026
LabelsBug 🐛help wantedgood first pickProtocol Related
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
WebdriverIO Version
latest
Node.js Version
latest
Mode
Standalone Mode
Which capabilities are you using?
N/AWhat happened?
A stale elementArray of $$() that no longer exists crashes with Index out of bounds! $$(h1) returned only 0 elements. when iterating it's properties like isDisplayed().
What is your expected behavior?
Even a stale instances of $$() should not crash when trying to iterator through the array to fetch any of it's properties. It's should simply return an empty results
How to reproduce the bug.
it.only('should be able to query isDisplayed on element no longer existing', async () => {
await browser.url('https://guinea-pig.webdriver.io/')
const h1 = $$('h1')
await expect(await h1.length).toBeGreaterThan(0)
await expect(await h1.map(el => el.isDisplayed())).toEqual([true, true])
await browser.url('about:blank')
await expect(await h1.map(el => el.isDisplayed())).toEqual([false, false])
})Relevant log output
[chrome 152.0.7977.64 mac #0-0] Index out of bounds! $$(h1) returned only 0 elements.
[chrome 152.0.7977.64 mac #0-0] Error: Index out of bounds! $$(h1) returned only 0 elements.
[chrome 152.0.7977.64 mac #0-0] at <anonymous> (webdriverio/packages/webdriverio/build/node.js:6287:15)
[chrome 152.0.7977.64 mac #0-0] at async Browser.wrapCommandFn (webdriverio/packages/wdio-utils/build/index.js:1006:23)
[chrome 152.0.7977.64 mac #0-0] at async <anonymous> (webdriverio/packages/webdriverio/build/node.js:748:36)
[chrome 152.0.7977.64 mac #0-0] at async Element.elementErrorHandlerCallbackFn (webdriverio/packages/webdriverio/build/node.js:9995:28)
[chrome 152.0.7977.64 mac #0-0] at async Element.wrapCommandFn (webdriverio/packages/wdio-utils/build/index.js:1006:23)
[chrome 152.0.7977.64 mac #0-0] at async Element.wrapCommandFn (webdriverio/packages/wdio-utils/build/index.js:1006:23)
[chrome 152.0.7977.64 mac #0-0] at async Element.elementErrorHandlerCallbackFn (webdriverio/packages/webdriverio/build/node.js:9972:24)
[chrome 152.0.7977.64 mac #0-0] at async Element.wrapCommandFn webdriverio/packages/wdio-utils/build/index.js:1006:23)
[chrome 152.0.7977.64 mac #0-0] at async Promise.all (index 1)
[chrome 152.0.7977.64 mac #0-0] at async Context.<anonymous> webdriverio/e2e/wdio/headless/test.e2e.ts:998:26)Code of Conduct
- I agree to follow this project's Code of Conduct
Is there an existing issue for this?
- I have searched the existing issues
Source: webdriverio/webdriverio