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

101
Vistas
Using querySelector for child elements

I've been using JavaScript for a few years writing scripts for automated tests for Desktop applications. However, I've recently transitioned into writing automated tests for web applications using Playwright. I've had to learn how to work with the html/css selectors. One thing that's eluded me is if there is a way (I feel like there must be) to specify an element on a page using a parent element and then the child element.

For example, I've got a pop up window which is a basic login page with ID and password. The textboxes for id and password do not have unique properties to point to, just <input type="text">. However, the entire login has the class of "page-options" which I know i can just grab with document.querySelector('.page-options');. Is there a way I can reference the inputs using await page.fill(); from playwright?

<div class="page-options">
    <div>
        <label>Page ID</label>
        <input type="text">
    </div>
    <div>
        <label>Page Password</label>
        <input type="text">
    </div>
</div>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Use the label text to id the required input:

await page.locator('text="Page ID" >> .. >> input').fill('name');  // label >> parent >> input
await page.locator('text="Page Password" >> .. >> input').fill('secret');

const value = await page.locator('text="Page Password" >> .. >> input').inputValue()  
expect(value).toEqual('secret')  
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can do something like this using the N-th element selector:

//For username
await page.locator('input[type="text"] >> nth=0').fill('value');

//For password
await page.locator('input[type="text"] >> nth=1').fill('value');
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