Skip to content

[Feature] Extend locator api with functions like waitForSelector() #8577

@MindaugasMateika

Description

@MindaugasMateika

Given the pseudo-POM below and the case where you would need to wait for an element for any reason, you'd have to repeat the selector in two places. It hurts reusability.

export class PageObject {
  private readonly page: Page
  private readonly someButton: Locator
  
  constructor(page: Page) {
    this.page = page
    this.someButton = this.page.locator('#someButtton')
  }
  
  async clickSomeButton() {
    await this.page.waitForSelector('#someButton')
    await this.someButton.click()
  }
}

While using the old method, you could set selector value once and then simply reuse the variable as much as you want:

POM with page actions
export class PageObject {
  private readonly page: Page
  private readonly someButton: string

  constructor(page: Page) {
    this.page = page
    this.someButton = ('#someButtton')
  }

  async clickSomeButton() {
    await this.page.waitForSelector(this.someButton)
    await this.page.click(this.someButton)
  }
}

It'd be nice if locator API would have an option to use functions like waitForSelector(). My use case involves only this function but there might be others.

Metadata

Metadata

Assignees

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