I'm facing an issue with a Jest and Selenium test. I'm trying to verify if an element is removed from the DOM after being clicked.
Here's what I've attempted:
test('User removes button after clicking on it', async (done) => {
await driver.navigate().to('myProjectUrl');
await driver.wait(until.elementLocated(By.css('.wrapper')), 10000);
await driver.findElement(By.id('buttonId')).click();
const deleteButton = await driver.findElement(By.id('buttonId'));
expect(deleteButton.isDisplayed()).not.toEqual(true);
done();
});
While this appears to be successful and the test passes, I'm encountering the following error message:
StaleElementReferenceError: stale element reference: element is not attached to the page document
I also tried a different approach:
test('User removes button after clicking on it', async (done) => {
await driver.navigate().to('myProjectUrl');
await driver.wait(until.elementLocated(By.css('.wrapper')), 10000);
await driver.findElement(By.id('buttonId')).click();
const buttonOrMessage = await driver.wait(until.elementLocated(By.id('buttonId)), 300, 'missing_button');
expect(buttonOrMessage).toEqual('missing_button');
done();
});
However, this method is giving me an error instead of the expected message.
If you have any suggestions or insights on what might be missing in my approach, your assistance would be greatly appreciated.