Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support waitForElementToBeRemoved #45

Open
umpox opened this issue Aug 20, 2020 · 2 comments
Open

Support waitForElementToBeRemoved #45

umpox opened this issue Aug 20, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@umpox
Copy link
Contributor

umpox commented Aug 20, 2020

waitFor and find* queries are supported but waitForElementToBeRemoved is not currently. It would be useful to add this async util to avoid having to write boilerplate code around waitFor and expect

waitForElementToBeRemoved - DOM Testing Library

@nickmccurdy nickmccurdy added the enhancement New feature or request label Aug 21, 2020
@avimar
Copy link

avimar commented Dec 26, 2020

waitForElementToBeRemoved seems to pass in a selector.
I'm needing to wait for an actual element to be removed. (I have a "continue" button on each stage of a form, and because of a
transition, there's a moment that you can see both "continue" buttons.)

Apparently, you can check if the elementHandle is still connected with await elementHandle.evaluate(el => el.isConnected) puppeteer/puppeteer#640 (comment)

@avimar
Copy link

avimar commented Dec 26, 2020

Here's my generic function that you can include under the MIT license to wait for an actual elementHandle to be removed. I didn't write the sleep function... it should be generic enough, though...

This code seems to work as a generic function:

function sleep(ms) {
	return new Promise((resolve) => {
		setTimeout(resolve, ms);
		});
	}
async function waitForElementHandleToBeRemoved(elementHandle,waitMax=5000,waitStep=100){
	const timeStart = new Date().valueOf();
	var elementVisible = true;
	var timeNow=timeStart;
	while((timeNow-timeStart)<waitMax && elementVisible){
		await sleep(waitStep);
		elementVisible = await elementHandle.evaluate(el => el.isConnected);
		timeNow = new Date().valueOf();
		}
	if(!elementVisible) return true;
	throw new Error('element still visible after '+waitMax+'ms');
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants