Playwright Wait Until Element is Visible

Profile picture for user arilio666

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.


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


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


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