Playwright Wait Until Element is Visible

Profile picture for user arilio666
Submitted by arilio666 on

In playwright, we can ensure whether an element is visible using the waitFor method. This article will discuss how we can assert the visibility of an element in a playwright.

Syntax:

(method) Locator.waitFor(options?: {
    state?: "visible" | "attached" | "detached" | "hidden" | undefined;
    timeout?: number | undefined;
} | undefined): Promise<void>

Example:

const ele = page.locator("#myDiv");
await ele.waitFor({state: "visible"})

Assertion

const locator = page.locator('element');
await expect(locator).toBeVisible();