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

180
Vistas
How to locate element having dynamic ids?

I want to locate this element:

<tr class=" category-2 saleproductname  " id="21" xpath="1">
<input class="check-box" id="BillInfo_4__isSelected" type="checkbox" value="true" xpath="1">

I am trying to locate the id, but the id is dynamic, this particular item can have id="BillInfo_0__isSelected, sometimes id="BillInfo_1__isSelected and I have to keep on changing them on code. Is there any solution to this? Here only the id = 21 is unique but unable to use this as well. I am trying to use id since the class is common and locates other elements too.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use the attribute selectors to find an element that:

  1. Starts with BillInfo_. [class^=""]
  2. Ends with __isSelected. [class$=""]

const element = document.querySelector('[id^="BillInfo_"][id$="__isSelected"]');

console.log(element);
<div id="BillInfo_4__isSelected"></div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Since id="21" is unique, query for that and use .find() (which will find within the parent) to access the input

cy.get('tr#21')
  .find('input')

In case there's several inputs in the same row

cy.get('tr#21')
  .children()
  .eq(0)          // first child element

If id="21" changes per build, it would be a good idea to add a data-cy attribute

<input class="check-box" id="BillInfo_4__isSelected" data-cy="my-input" ... />
cy.get('[data-cy="my-input"]')
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