I have searched on Google and the SO site and I get answers for JAVA but do not seem to get answers for node.js
I have a web app that takes time to load. I would like
Writing asynchronous function to avoid this problem
(async function() {
let url = args[0];
await driver.get(url);
driver.quit();
})();
I came up with this approach because it maintains the chainable promise syntax so that I can write this: await waitFind(By.id('abc')).click()
const waitFind = (locator) => {
return driver.findElement(async () => {
await driver.wait(until.elementLocated(locator));
return driver.findElement(locator);
});
}
I stumbled upon an answer to my question
So to wait for an element to appear we have to:
driver.wait(function () {
return driver.isElementPresent(webdriver.By.name("username"));
}, timeout);
I usually use this way:
var el = driver.wait(until.elementLocated(By.name('username')));
el.click();
This is the only thing that is working for me:
const element = By.id('element');
driver.wait(until.elementLocated(element));
const whatElement = driver.findElement(element);
driver.wait(until.elementIsVisible(whatElement), 5000).click();
You can register a listener on webdriver.wait
by using then()
return driver.wait(until.elementLocated(By.name('username')), 5 * 1000).then(el => {
return el.sendKeys(username);
});