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

408
Visualizações
Trouble selecting a classname with waitForSelector in Playwright

I am scraping a page and this is the data I'm looking for:

<div class="account-balance">
<span class="name">Total balance</span>
<span class="balance">$10</span>
</div>

If I look for the text "total balance," I can find it:

await page.waitForSelector('text=Total balance');

But if I try to find a classname, it times out:

await page.waitForSelector('.account-balance');

I've tried waitForSelector as well as locator, and whenever I target a classname like this, it fails. Thanks for any help.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

There may be possibility that there are multiple class with same value. You can try with xpath.

await page.waitForSelector(xpath=//div[@class='account-balance']);

Or

await page.waitForSelector(xpath=//span[text()='Total balance']/..);
about 4 years ago · Juan Pablo Isaza Relatório

0

You have to go to the class name for the text Total balance and then wait for it.

await page.waitForSelector('.account-balance > .name');
about 4 years ago · Juan Pablo Isaza Relatório

0

Instead of using a selector engine (like text or css), try using this

span:has-text('Total balance');

Also, check if there are multiple text with Total balance. In that case, you case use the nth matcher to select the text - for e.g. you can use this locator to select the 3rd instance of Total balance

await page.locator(':nth-match(:text("Total balance"), 3)').click();
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