Encountering the persistent issue of receiving the error message
StaleElementReferenceError: stale element reference: element is not attached to the page document
every time I attempt to extract the text from a page body using Selenium.
Numerous attempts have been made to resolve this, but unfortunately without success.
Code snippet:
function eduMobile(driver)
{
driver.get(process.env.URL)
// PIN login
const pinEntry = driver.findElement(By.xpath('//*[@id="inputPin"]'))
pinEntry.sendKeys(process.env.PIN)
const pinOkBtn = driver.findElement(By.xpath('/html/body/div/form/input[2]'))
pinOkBtn.click()
// get body
var mobile_body = driver.findElement(By.xpath("/html/body"))
mobile_body.getText().then(function (text) {
console.log(text);
});
}
An attempt was made to rectify the issue with the following code snippet, which also yielded no success:
mobile_body.getText().then(function (text) {
console.log(text);
});
Initialization of my driver:
let driver = new webdriver.Builder()
.forBrowser(Browser.CHROME)
.setChromeOptions(new chrome.Options().headless())
.build()
Complete error message received:
C:\Users\andri\node_modules\selenium-webdriver\lib\error.js:522
let err = new ctor(data.message)
^
StaleElementReferenceError: stale element reference: element is not attached to the page document
(Session info: headless chrome=102.0.5005.115)
at Object.throwDecodedError (C:\Users\andri\node_modules\selenium-webdriver\lib\error.js:522:15)
at parseHttpResponse (C:\Users\andri\node_modules\selenium-webdriver\lib\http.js:549:13)
at Executor.execute (C:\Users\andri\node_modules\selenium-webdriver\lib\http.js:475:28)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async thenableWebDriverProxy.execute (C:\Users\andri\node_modules\selenium-webdriver\lib\webdriver.js:735:17) {
remoteStacktrace: 'Backtrace:\n' +
'\tOrdinal0 [0x0064D953+2414931]\n' +
...additional stack trace lines...
'\tRtlGetFullPathName_UEx [0x777E8FBD+1165]\n'
}
Your help in resolving this matter would be greatly appreciated!