Skip to content

[Question] How to wait for a Locator to be visible? #9179

@TimeInvestor

Description

@TimeInvestor

Context:
In Page Object Model, I would create a page object like this

import { Locator, Page } from '@playwright/test';

export class PlaywrightDevPage {
  readonly page: Page;
  readonly getStartedLink: Locator;

  constructor(page: Page) {
    this.page = page;
    this.getStartedLink = page.locator('text=Get started');
  }

  async goto() {
    await this.page.goto('https://playwright.dev');
    // duplicate selector appearence
    await this.page.waitForSelector(''text=Get started'');
  }
}

Because Locator.isVisible() does not wait for the element to become visible and returns immediately, I have to use waitForSelector method. But there is no supported function like page.waitForSelector(locator: Locator) or page.waitForLocator(locator: Locator) or Locator.waitUtil(state: State).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions