Categories
JavaScript Answers

How to wait till element is displayed with JavaScript Selenium WebDriver?

Spread the love

Sometimes, we want to wait till element is displayed with JavaScript Selenium WebDriver.

In this article, we’ll look at how to wait till element is displayed with JavaScript Selenium WebDriver.

How to wait till element is displayed with JavaScript Selenium WebDriver?

To wait till element is displayed with JavaScript Selenium WebDriver, we use the wait and elementIsVisible methods.

For instance, we write

const el = await driver.findElement(By.id(`import-file-acqId:${acqId}`));
await driver.wait(until.elementIsVisible(el), 100);
await el.sendKeys(file);

to call findElement to find the element by its iD.

Then we call driver.wait to wait for the element until it’s visible and time out in 100ms.

Then we call sendKeys to press the key on it.

Conclusion

To wait till element is displayed with JavaScript Selenium WebDriver, we use the wait and elementIsVisible methods.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *