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

257
Views
Cypress: how to split numbers found in divs?

I have a test that is going into an elements span > div but there are two of them so when I run the test it concatenates both of them into one number 13,900879,210. I need it to give me them separately to compare them such as 13,900 and 879,210. Here is my code. Can anyone help with this?

cy.get(`div[id]=2`).find('span').find('div').invoke('text').then((nums) => {
  cy.log(nums) // 13,900879,210
})
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can't really split the combined text (unless you know how many characters in each).

You can get the texts individually,

cy.get(`div[id="2"]`).find('span').find('div')
  .then($divs => {
    const nums = [...$divs].map(div => div.innerText)
    cy.log(nums) // ['13,900', '879,210']
  })

where

  • $divs is a jQuery object holding both divs
  • [...$divs] converts the jQuery object to an array of (raw) elements
  • .map(div => +div.innerText) maps elements into their text values

To work with integers, add a + to the map

cy.get(`div[id="2"]`).find('span').find('div')
  .then($divs => [...$divs].map(div => +div.innerText))
  .should('deep.eq', [13900, 879210])
about 4 years ago · Santiago Trujillo Report

0

You can use Cypress' .each() function to iterate through each element yielded.

cy.get(`div[id]=2`).find('span').find('div').each(($el) => {
  // $el is a JQuery element, so we can use JQuery functions like `.text()`
  cy.log($el.text());
});
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!