I am attempting to wait for a component to finish rendering an animation I have. It’s a splash screen, that when done, exposes the main home page. Here is the life cycle of the div
in question
// When page loads and as animation is occurring
<div id="splash-screen">...</div>
// After the animation is finished
<div id="splash-screen" class="animate finished">...</div>
The splash screen and the root of the app are separate. So within my body
tag, I have:
<body>
<div id="splash-screen" class="animate finished">...</div>
<div id="root" class="root">...</div>
</body>
I have attempted several things to wait for this specific div to appear, but I keep getting an error thrown. I NEED to wait for this animation to finish because the k6 browser has issues with selecting a button as the animation is occurring. I just want to be able to tell the test “Wait for this specific div (i.e. animation div) to finish, after it has appeared, continue.” Currently, I have to set it to sleep
to get past the animation screen reliably. I feel like I am missing something so simple, but I am not sure what it is. Why is it not able to just wait for the div with ID and class to appear? Below I will post what I have tried and show the error presented.
// GoError: waiting for selector "//div[@id=\"splash-screen\"][@class=\"animate finished\"]": DOMException: Failed to execute 'evaluate' on 'Document': The node provided is '#document-fragment', which is not a valid context node type.
page.waitForSelector('//div[@id="splash-screen"][@class="animate finished"]', {
state: 'visible',
timeout: 10000,
});
// GoError: waiting for selector "//div[@id=\"splash-screen\"][@class=\"animate finished\"]": DOMException: Failed to execute 'evaluate' on 'Document': The node provided is '#document-fragment', which is not a valid context node type.
page.waitForSelector('//div[@class="animate finished"]', {
state: 'visible',
timeout: 10000,
});
//GoError: waiting for "//div[@id=\"splash-screen\"][@class=\"animate finished\"]": execution context changed; most likely because of a navigation
const splashScreen = page.locator('//div[@id="splash-screen"][@class="animate finished"]');
splashScreen.waitFor({ state: 'visible', timeout: 10000 });
// This one is weird because there is not navigation happening on the page. The animation just turns off after the class is assigned.
// GoError: waiting for "div#splash-screen.animate.finished": timed out after 10000ms
const splashScreen = page.locator('div#splash-screen.animate.finished');
splashScreen.waitFor({ state: 'visible', timeout: 10000 });
// Uncaught (in promise) GoError: waiting for selector "div#splash-screen.animate.finished": timed out after 10000ms
page.waitForSelector('div#splash-screen.animate.finished', {
state: 'visible',
timeout: 10000,
});
Any help would be greatly appreciated!!!