Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

303
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda