Paul
Paul

Reputation: 259

Playwright - do while selector not found on page

I am using PlayWright and want to perform an operation whilst an element is not found in the DOM.

My code looks similar to:

while(!page.locator('.list-empty'))
 {
   await removeAllRoles();
 }

this doesnt work. How can i achieve this?

Upvotes: 2

Views: 3769

Answers (1)

Yevhen Laichenkov
Yevhen Laichenkov

Reputation: 8662

You need to use isVisible method for that.

while(!(await page.locator('.list-empty').isVisible())) {
  // do something
}

Also, you can use isHidden method. It's the opposite of isVisible.

while(await page.locator('.list-empty').isHidden()) {
  // do something
}

Upvotes: 1

Related Questions