So guys, the same problem as a lot of people! When i trying to interact (Click) on a element into the page a have problems with the error:
Error Message
"Failed: stale element reference: element is not attached to the page document"
I undertood the concept of the page changing the DOM, but i really cannot solve the problem. Some advices? (element with error: await processoLista.click();)
console.log('Testing Pesquisa Assunto ...');
beforeAll(async function () {
await browser.get(browser.params.URL_PROCESSO).then(function () {
const EC = protractor.ExpectedConditions;
})
});
it('Deve escolher um ASSUNTO PRINCIPAL e verificar os resultados', async function () {
try {
if (await browser.findElements(by.id('filtro_assuntos')).toEqual(""));
} catch{
const btnMaisFiltros = element(by.id('maisFiltros'))
const placeAssunto = element(by.css('[placeholder = "Assunto"]'))
const listAssuntos = element.all(by.className('mat-option-text')).get(2)
const habilitaAssuntoP = element(by.className('mat-slide-toggle-bar'))
const aplicar = element(by.className("aplicar"))
const processoPainel = element(by.className('cdk-overlay-pane'))
const classText = element(by.className('texto'))
const assunto = element(by.partialLinkText('Abandono'))
await btnMaisFiltros.click();
await browser.wait(EC.presenceOf(placeAssunto));
await browser.wait(EC.elementToBeClickable(placeAssunto));
await placeAssunto.click();
await browser.wait(EC.presenceOf(listAssuntos));
await browser.wait(EC.elementToBeClickable(listAssuntos));
await listAssuntos.click();
await habilitaAssuntoP.click();
await browser.wait(EC.presenceOf(aplicar));
await browser.wait(EC.elementToBeClickable(aplicar));
await aplicar.click();
const processoLista = await element.all(by.className('identificacao')).get(0);
await browser.wait(EC.titleContains('.'));
await browser.wait(EC.presenceOf(processoLista));
await browser.wait(EC.elementToBeClickable(processoLista));
await processoLista.click();//HE CANNOT CLICK HERE! SOMETIMES HE CAN AND SOMETIMES I HAVE THE ERROR
await browser.wait(EC.presenceOf(classText));
await browser.wait(EC.presenceOf(assunto));
expect(await assunto.getText()).toContain('Abandono')
}
})```