Mirza Asim Baig
Mirza Asim Baig

Reputation: 71

How to find text in Cypress when value attribute is not given?

I have Three text-boxes. Input 10 in first text-box and you will get 9.5 and 10.5 in next 2 text-boxes. Need to verify the values of auto calculated text-boxes.

  1. This is the application enter image description here
  2. This is what i Have tried

    • cy.get('#LSL').should('have.text', '9.5');

    • cy.get('#LSL').should('contains', '9.5');

  3. Issue that I am getting is enter image description here

text that it finds is blank

Upvotes: 1

Views: 315

Answers (2)

Pranawa Mishra
Pranawa Mishra

Reputation: 51

Use

cy.get('#LSL').invoke('val').should('contain', 9.5);

Upvotes: 2

Alapan Das
Alapan Das

Reputation: 18634

When the value attribute is not present for any input field, the next is to look for for innerHTML or innerText. Mind giving this a try:

cy.get('#LSL').invoke('text').should('contain', 9.5);

Upvotes: 1

Related Questions