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

102
Visualizações
Get how mant <li> under <ul> using Puppeteer

I have the following code:

it('7.1.8 - In Platform admin could review all ongoing and published notifications', async () => {
    const allNotificationList = await page.waitForXPath(
      '//header[contains(@class,"ant-layout-header")]//ul[contains(@class,"Notifications_banner-notifications")]',
    );
    expect(allNotificationList.length).not.toBe(0);
  });

allNotificationList gets the ul tag and I want to check how many li tag are under the selected ul tag.

Does anyone knows how to achieve this using Puppetter?

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

0

You can use page.$x (or someElement.$x) to return an ElementHandle[] (page.waitForXPath returns a single ElementHandle):

const allNotificationList = await page.$x(
  '//header[contains(@class,"ant-layout-header")]//ul[contains(@class,"Notifications_banner-notifications")]',
);
expect(allNotificationList.length).not.toBe(0);

I don't think it actually waits for the elements though, so you might want to add the following line first:

await page.waitForXPath(
  '//header[contains(@class,"ant-layout-header")]//ul[contains(@class,"Notifications_banner-notifications")]',
);
about 4 years ago · Juan Pablo Isaza Relatório

0

I have no solution for this with Xpath, but if you are open to shape the Xpath to CSS selector, then the following will do what you need. Using childElementCount.

const selector = 'header.ant-layout-header * ul.Notifications_banner-notifications'
const childCount = await page.$eval(selector, el => el.childElementCount)
expect(childCount).toBeGreaterThan(0)
about 4 years ago · Juan Pablo Isaza Relatório

0

(await page.$$('.Notifications_banner-notifications li')).length
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