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

Want to validate the part of a string shouldn't be null

I have this following element which contain a string for Practitioner, its value is 1- zzz. How to validate after - it shouldn’t be null. Even if there is a string or empty. It shouldn’t print null. Also want to select the value under Practitioner (currently hard coded the position of the element as 2)

<div class="styles__container___BfTYi">
<div class="styles__subHeader___18Yg1">Practitioner</div>
<div class="styles__data___1senX">1- zzz</div>
</div>

enter image description here

I have the following code to retrieve the text,

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

 cy.get(pageSelector.practitionerValidator).eq(2).then(function($getText) {
        let practitionerName = $getText.text();
        var validateLastName = practitionerName.split(' ');
        cy.log(validateLastName[1]);
        expect(validateLastName[1]).to.not.equal('null');
    })

enter image description here

>Solution :

You can directly check that the entire string is not null like this:

cy.get('.styles__data___1senX').then(($ele) => {
  expect($ele.text()).to.not.be.null
})

Or if you want to check that your inner text is not empty you can do:

cy.get('.styles__data___1senX').then(($ele) => {
  expect($ele.text()).to.not.be.empty
})

You can find the selector from the text Practitioner like this:

cy.contains('Practitioner')
  .parent()
  .within(() => {
    cy.get('div[class*="styles__data__"]').then(($ele) => {
      expect($ele.text()).to.not.be.null
    })
  })
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