I am encountering Stale Element Error as below
let err = new ctor(data.message)
^
StaleElementReferenceError: Error executing JavaScript
at Object.throwDecodedError (C:\Users\dev\coding\bjak-japan\node_modules\selenium-webdriver\lib\error.js:521:15)
at parseHttpResponse (C:\Users\dev\coding\bjak-japan\node_modules\selenium-webdriver\lib\http.js:514:13)
at Executor.execute (C:\Users\dev\coding\bjak-japan\node_modules\selenium-webdriver\lib\http.js:446:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Driver.execute (C:\Users\dev\coding\bjak-japan\node_modules\selenium-webdriver\lib\webdriver.js:740:17) {
remoteStacktrace: ''
}
Node.js v20.13.1
I have tried to use try catch to avoid catching this error in nodejs but somehow this error is printed in my terminal and it stopped my test case from running. I need help to avoid this error from printing in my terminal
Below is an example of my try catch code
while (attempt < maxAttempts) {
try {
const plan3_checkbox = await page.findElement(
By.xpath(
"//div[@id='baseInformationArea']/div/div[2]/div/div[2]/div/div[2]/div[3]/div/label",
),
);
await plan3_checkbox.click();
attempt = 0;
break;
} catch (error) {
attempt++;
if (attempt === maxAttempts) {
attempt = 0;
throw error;
}
continue;
}
}