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

379
Vistas
How to adding values from dynamic elements and verifying the result

Similarly to this question. How add two values[1,2 elements] and verify its equal to result[3 element]

from the below HTML structure I need to add A(element) & B(element) and verify the sum is equal to A+B(element) its complex for me since A & B are dynamic and they can or cannot be present depending on the changes from the user.

enter image description here

I tried to use the below script.

cy.get('[data-cy="Selected in Final InterviewofferBreakUpTableBodyCellRenderer"] >span').invoke('text')

But it's yielding both the text, i only need the number.

enter image description here

I need help in making a test that won't fail even if only one element A or B is present.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can do something like this:

cy.contains('span', 'Final Interview Selects')
  .next()
  .invoke('text')
  .then((sum) => {
    cy.contains('span', 'Selected - Not Offered')
      .next()
      .invoke('text')
      .then((A) => {
        cy.contains('span', 'Selected in Final Interview')
          .next()
          .invoke('text')
          .then((B) => {
            expect(+sum).to.eq(+A + +B)
          })
      })
  })

You can do something like this if some of the elements are not visible.

const A = 0,
  B = 0
cy.get('body')
  .then(($body) => {
    if (
      '$body:not(:contains("Selected - Not Offered"))' &&
      '$body:contains("Selected in Final Interview")'
    ) {
      A = 0
      cy.contains('span', 'Selected in Final Interview')
        .next()
        .invoke('text')
        .then((num) => {
          B = +num
        })
    }

    if (
      '$body:contains("Selected - Not Offered")' &&
      '$body:not(:contains("Selected in Final Interview"))'
    ) {
      B = 0
      cy.contains('span', 'Selected - Not Offered')
        .next()
        .invoke('text')
        .then((num) => {
          A = +num
        })
    }

    if (
      '$body:not(:contains("Selected - Not Offered"))' &&
      '$body:not(:contains("Selected in Final Interview"))'
    ) {
      A = 0
      B = 0
    }
  })
  .then(() => {
    cy.contains('span', 'Final Interview Selects')
      .next()
      .invoke('text')
      .then((sum) => {
        expect(+sum).to.eq(A + B)
      })
  })

about 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