This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Helper function to wait for an element to appear or disappear. | |
| * @param {string} selector - The CSS selector to query. | |
| * @param {boolean} [shouldExist=true] - If true, waits for the element to exist. If false, waits for it to not exist. | |
| * @param {number} [timeout=3000] - Max time to wait in milliseconds. | |
| * @returns {Promise<Element|null>} A promise that resolves with the element (if found) or null (if timed out or disappearing). | |
| */ | |
| async function waitForElement(selector, shouldExist = true, timeout = 3000) { | |
| const startTime = Date.now(); | |
| while (Date.now() - startTime < timeout) { |