0

I'm trying to check the value of the value field inside a div. this value is not reflected to a string or a int in the div value, only in his attribute:

<input as-automation="" type="text" placeholder="Put the initial value here" value="999.99">

please look a value of 999.99, how can I reach it? I tried valueof, contains, eq, nothing worked..

I want to find the way to reach this value by cypress.

Mads Brugger
  • 242
  • 9
Omer Naim
  • 1
  • 1
  • 1
    Does this answer your question? [How to get the text input field value to a const and log that value in Cypress.io](https://stackoverflow.com/questions/51793521/how-to-get-the-text-input-field-value-to-a-const-and-log-that-value-in-cypress-i) – TesterDick Jan 19 '23 at 22:54

3 Answers3

0

You should be able to reference the element's value by the key value, either through the Chai assertion (via cy.should()) or in cy.its().

cy.get('input').should('have.value', '999.99');
...
cy.get('input').its('value').then((value) => {
  // other code where you do something with the `value` variable
})
agoff
  • 5,818
  • 1
  • 7
  • 20
0

There are a few ways to check it.

const value = "999.99";
cy.get("input").should("have.value", value);

cy.get("input").should(($input) => {
  const val = $input.val();

  expect(val).to.eq(value);
});

cy.get("input").invoke("val").should("eq", value);

Here is a working example.

jjhelguero
  • 2,281
  • 5
  • 13
0

Another way to do this is:

cy.get('input').should('have.attr', 'value', '999.99')
Alapan Das
  • 17,144
  • 3
  • 29
  • 52