Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

377
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!