Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

97
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

(await page.$$('.Notifications_banner-notifications li')).length
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda