10 examples of 'javascript wait for element to exist' in JavaScript

Every line of 'javascript wait for element to exist' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
15wait(elem) {
16 browser.waitForExist(elem);
17}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

92async findWithWait(element) {
93 try {
94 await this.driver.wait(webdriver.until.elementLocated(element), Twait);
95 return await this.driver.findElements(element);
96 } catch(err) {
97 return null;
98 }
99}
98async findWithWait(element) {
99 try {
100 await this.driver.wait(webdriver.until.elementLocated(element), Twait);
101 return await this.driver.findElements(element);
102 }
103 catch (err) {
104 return null;
105 }
106}
40async waitUntilLocated(element, Twaiting) {
41 let counter = Twaiting;
42 if (counter === undefined) counter = 180;
43 try {
44 do {
45 await this.driver.sleep(300);
46 if (await this.isElementLocated(element)) return true;
47 } while (counter-- > 0);
48 return false;
49 }
50 catch (err) {
51 return false;
52 }
53}
121waitForElement(name) {
122 this.t.expect(Selector(`[data-test-id="${name}"]`, OPTS))
123}
71getWhenPresent(selector) {
72 return this.app.waitForExist(selector).element(selector);
73}
13async waitForChildElementToAppear() {
14 return await this.driver.wait( until.elementLocated( by.id( 'elementappearschild' ) ), this.explicitWaitMS, 'Could not locate the child element within the time specified' );
15}
41function waitForElement(selector, callback) {
42 if (document.querySelector(selector)) {
43 return callback()
44 } else {
45 setTimeout(waitForElement.bind(this, selector, callback), 300)
46 }
47}
209function waitForElement(selector, callback) {
210 waitFor(function() {
211 return !!$(selector).length;
212 }, callback);
213}
77export function waitForElementInVisibility (_element ) {
78 return browser.wait(expCond.invisibilityOf(_element)).catch((error) => console.log(`${_element.locator()} waitForElementInVisibility:`, error));
79}

Related snippets