Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

305
Views
Playwright: How to search for an element that has a specific empty tag in the element tree?

How to search for an element that has a specific empty tag in the element tree in Playwright tests (using their test-runner)?

I have tried an empty text filter (obviously not the best idea)

// variant 1
page.locator(`[aria-label="label name"].has(span:text-is(""))`);
// variant 2
page.locator(`[aria-label="label name"].has(div[role="button"] span[text=""])`);

but got error

locator.textContent: Unexpected token "" while parsing selector "[aria-label="label name"]"

The only solution that works for me is to check each text content using JS, for example:

const locator = page.locator('div[role="button"] >> span');
const elementsCount = await locator.count();
for(let i = 0; i < elementsCount; i++) {
  const spanTextContent = await locator.nth(i)?.textContent();
  return spanTextContent === '' ? locator.nth(i) : null;
}

Another example that gives Unexpected token "" while parsing selector error:

    locator = page.locator(`body:has(div[class="L3eUgb"] >> a >> text="About")`);
    console.log(`locator.count(): ${await locator.count()}`);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It seems that you're mixing a little bit wrongly CSS selectors and custom Playwright's pseudo-classes.

This should work for you:

page.locator('div[role="button"] >> span >> text=""')

UPDATE:

page.locator(`body:has(div[class="L3eUgb"]) >> a >> text="About"`)

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!