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

343
Vistas
puppeteer page.type() select second element/class

I'm trying to select and edit the first text input of the third div with "nxcard" class

this is the page structure :

<div>
  <div class="nxcard">
    <h3>Lorem ipsum dolor sit amet.</h3>
    <form>
      <input type="number" />
      <input type="text" />
    </form>
  </div>
  <div class="nxcard">
    <h3>Lorem ipsum dolor sit amet.</h3>
    <form>
      <input type="number" />
      <input type="text" />
    </form>
  </div>
  <div class="nxcard">
    <h3>Lorem ipsum dolor sit amet.</h3>
    <form>
      <input type="number" />
      <!-- the input I want to select using pupeteer : -->
      <input type="text" />
    </form>
  </div>
</div>

this is the original code (how I'd have done it without puppeteer)

  const loginCard = document.getElementsByClassName("nxCard")[2];
  const loginForm = loginCard.getElementsByTagName("form")[0];
  const loginUserName = loginForm.getElementsByTagName("input")[1];
  loginUserName.value = "user1";

and this is how I've tried to do the same thing using puppeteer

  await page.type(".nxcard[2] form input[1]", "user1");
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I was able to solve it using the following css selector

await page.type(".nxcard:last-child input:nth-child(1)" , "user1")

src : https://www.w3schools.com/cssref/css_selectors.asp

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