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

773
Vistas
How to check if an element is in the document with playwright?

I want to test if an element had been rendered. So I want expect that if is present. Is there a command for this?

await page.goto(‘<http://localhost:3000/>');
const logo = await page.$(‘.logo’)

// expect(logo.toBeInDocument())
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Since the use of ElementHandle (page.$(), page.$$()) is discouraged by the Playwright Team, you could use the Locator object and the count() method:

expect(await page.locator('data-testid=exists').count()).toBeTruthy();
expect(await page.locator('data-testid=doesnt-exist').count()).toBeFalsy();

If you want to check if the element is rendered (I assume you mean visible) you could use the toBeVisible assertion:

await expect(page.locator('data-testid=is-visible')).toBeVisible();
over 4 years ago · Santiago Trujillo Denunciar

0

If you query one element with page.$(), you can simply use:

const logo = await page.$('.logo');
if (logo) {

}

Similarly if you query multiple elements with page.$$():

const logo = await page.$$('.logo');
if (logo) {

}

Since this example returns (after awaiting) an array of element handles, you can also use property length in the condition:

const logo = await page.$$('.logo');
if (logo.length) {

}

The key in all these examples is to await the promise that page.$() and page.$$() return.

over 4 years ago · Santiago Trujillo Denunciar

0

await expect(page.locator('.logo')).toHaveCount(1)
over 4 years ago · Santiago Trujillo 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