Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cypress .replace() method

Code
I want to put found text in a list then .log() it

I copied the .replace() method from my previous code but I only know how to make it put a space after 5 letters. Is there a way to make it separate each "word" from a different div’s? My log looks like this log and I want it to look like:
isSystemObject name description avatar tags isSystemObject name description avatar tags

Appreciate all the help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the each() method to loop over all elements, extract the text and then apply the replace() method like this:

cy.get('#header').find('#label').each(($ele) => {
  const nazwy = $ele.text().trim().replace(/(.{5})/g,"$1 ")
  cy.log(nazwy)//prints label texts one by one
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading