Categories
JavaScript Answers

How to wait for a condition with Protractor and JavaScript?

Spread the love

Sometimes, we want to wait for a condition with Protractor and JavaScript.

In this article, we’ll look at how to wait for a condition with Protractor and JavaScript.

How to wait for a condition with Protractor and JavaScript?

To wait for a condition with Protractor and JavaScript, we use the wait method.

For instance, we write

const EC = protractor.ExpectedConditions;
const e = element(by.id("xyz"));
browser.wait(EC.presenceOf(e), 10000);
expect(e.isPresent()).toBeTruthy();

to get the element with ID xyz with by.id.

Then we call wait to wait for the presence of the element with presenceOf.

It times out after 10000ms.

Then we check if the element is present with isPresent.

Conclusion

To wait for a condition with Protractor and JavaScript, we use the wait method.

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 *