Selenium WebDriver wait till element is displayed
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);
You can register a listener on webdriver.wait
by using then()
driver.wait(until.elementLocated(By.name('username')), 5 * 1000).then(el => {
el.sendKeys(username);
});
You don't need a custom function, you can just do this:
let el = await driver.findElement(By.id(`import-file-acqId:${acqId}`));
await driver.wait(until.elementIsVisible(el),100);
await el.sendKeys(file);
See the docs here.