I am looking for a way to wait for element to be displayed in DOM and throw a timeout exception when it is not displayed in a give time. How can I accomplish that? I have this take, but sure it will not work.
function waitForElement(element, timeout) {
return new Promise((resolve, reject) => {
const t = setTimeout(() => {
let queryInterval = setInterval(() => {
const isElementVisible = document.contains(element);
if (!isElementVisible) {
clearInterval(queryInterval);
clearTimeout(t);
resolve(true);
}
}, 10);
console.log("Timeout!");
clearTimeout(t);
reject("Time Out!");
}, timeout);
});
}