[🐛 Bug]: The element inside an ElementArray is staled, cannot be refetched and an infinite loop occures
#10.263 geöffnet am 25. Apr. 2023
Repository-Metriken
- Stars
- (6.029 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 15T 15h) (48 gemergte PRs in 30 T)
Beschreibung
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
WebdriverIO Version
8.3.9
Node.js Version
v16.13.2
Mode
WDIO Testrunner
Which capabilities are you using?
Electron service
Electron V22.3.6
What happened?
When looping through an ElementArray, an infinite loop occurs if an element becomes stale. To see this for yourself, run the code below in How to reproduce the bug with the WebdriverIO-Mocha-BDD Boilerplate project.
I have attempted to investigate the error and found that refetchElement() in middlewares.js is called, and the element is found with a new element ID. However, it will still search for the first element, which is stale. For instance, you can see in the logs, that the last element ID found is ELEMENT-19298 (The number is very large because we are in an infinite loop), but the error will still be "The element with reference ELEMENT-11 is stale."
I think it's similiar to #6798
What is your expected behavior?
After first try, either the element should be found or the not found error be thrown.
PS: I expected to see something in the logs when an element becomes stale, but there aren't any logs. In my humble opinion, it would be beneficial to add some logs for this case. Additionally, I have not seen any documentation indicating that if an element is stale, WebdriverIO will attempt to refetch it. The file name is also "middlewares," making it difficult to spot the error. Perhaps some refactoring there would make sense. I would be happy to hear your thoughts on this as well. Another idea is to add a counter to prevent confusion in the future.
How to reproduce the bug.
Add console.log(err) to middlewares.js so you can see the stale element error.
catch (err) {
if (err.name === 'stale element reference') {
const element = await refetchElement(this, commandName);
this.elementId = element.elementId;
this.parent = element.parent;
console.log(err); //ADD THIS LINE
return await fn(commandName, commandFn).apply(this, args);
}
throw err;
}
The test:
describe('Stale element', () => {
it('Stale element infinite loop', async () => {
await browser.url('https://webdriver.io/docs/gettingstarted');
const elem = await browser.$('ul.theme-doc-sidebar-menu');
const tableContentRows = await elem.$$('li');
let i=0;
for (const tableContentRow of tableContentRows) {
i++;
if (i > 5) {
await browser.url('https://webdriver.io/docs');
await browser.url('https://webdriver.io/docs/gettingstarted');
}
const elem2 = await tableContentRow.$('.menu__link');
}
await browser.debug();
})
})
Relevant log output
...
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:18:32)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] ELEMENT-19172
[0-0] err
[0-0] stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:41:28)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] ELEMENT-19186
[0-0] err
[0-0] stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:18:32)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] ELEMENT-19200
[0-0] err
[0-0] stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:41:28)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] ELEMENT-19214
[0-0] err
[0-0] stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:18:32)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] ELEMENT-19228
[0-0] err
[0-0] stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:41:28)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] ELEMENT-19242
[0-0] err
[0-0] stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:18:32)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] ELEMENT-19256
[0-0] err
[0-0] stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:41:28)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] ELEMENT-19270
[0-0] err
[0-0] stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C://webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:18:32)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] ELEMENT-19284
[0-0] err
[0-0] stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:41:28)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] ELEMENT-19298
[0-0] err
[0-0] stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] stale element reference: stale element reference: The element with reference ELEMENT-11 is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
[0-0] at getStaleElementError (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/utils.js:172:19)
[0-0] at DevToolsDriver.findElementFromElement (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/commands/findElementFromElement.js:19:15)
[0-0] at runMicrotasks (<anonymous>)
[0-0] at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0-0] at async Element.wrappedCommand (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/devtools/build/devtoolsdriver.js:127:26)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.elementErrorHandlerCallbackFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/webdriverio/build/middlewares.js:18:32)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
[0-0] at async Element.wrapCommandFn (file:///C:/project/webdriverIO-with-mochaBDD/node_modules/@wdio/utils/build/shim.js:72:29)
...
...
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