I have a few text fields which when I login as a specific user (rights of a read only) , all the text fields are not allowed to be edited. I am trying to automate this page in Cypress.

I tried using :

cy.get(element).should("have.text", readonly,readonly).

Both failed.

Please let me know if anyone has any other options.

  • What's the actual DOM you're trying to test? Are the inputs disabled? Do they have the attribute readonly set (is that what you're trying to test with "have.text")? Something else (e.g. code behind just ignores whatever the user tries to type in)?
    – jonrsharpe
    Commented Jul 15, 2022 at 7:42
  • The DOM is an input field (a text box) . They dont have an attribute "readonly" . Currently there is no value in the text boxes, Commented Jul 15, 2022 at 8:20
  • Can you paste the relevant DOM? Disabling can be implemented in many ways - your code should be align with the specific way. Commented Jul 15, 2022 at 9:36
  • Here is one example of it. there are 15 text fields . all of them are non editable. Commented Jul 16, 2022 at 12:27
  • 1
    Past the ACTUAL dom from view page source so we can see the input field, any label field and any other wrappers immediately around them. We can guess endlessly about what it might be but you can tell us (and then we can help you) by showing us the HTML code. Commented Jul 16, 2022 at 23:52

1 Answer 1


You could use the next code:

cy.get(element).should('have.attr', 'readonly', 'readonly')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.