Cypress: TypeError: cy.get(...).text is not a function

Created on 1 Jul 2019  路  5Comments  路  Source: cypress-io/cypress

Cypress was working fine with the below code but currently throwing error cy.get(...).text is not a function

context('Testing Application', () => {
    beforeEach(() => {
        cy.test();
    })
    it('Verify Application List', () => {
        cy.get('.MuiButtonBase-root').each((item, index) => {
            cy.get(`:nth-child(${index + 1}) > .ButtonBase-root > .title__text`)
            .text()
                .then((itemDesc) => {
                    cy.get(`:nth-child(${index + 1}) > .ButtonBase-root`).click();
                    cy.get('.title__text').text().should('eq', itemDesc);

"devDependencies": {
    "@cypress/snapshot": "^2.1.3",
    "cypress": "^3.3.2",
    "cypress-image-snapshot": "^3.0.2",
    "cypress-slack-reporter": "^0.3.1",
    "mocha": "^5.2.0",
    "mocha-junit-reporter": "^1.23.0",
    "mocha-multi-reporters": "^1.1.7",
    "mochawesome": "^4.0.0",
    "mochawesome-merge": "^2.0.1",
    "mochawesome-report-generator": "^4.0.0",
    "regenerator-runtime": "^0.13.2"
  }
question

All 5 comments

Above code was working before, but currently throwing error "cy.get(...).text is not a function"

.text() is not a Cypress command. So the error you are getting is accurate.

Perhaps you had a custom command written for .text() in one of the files in cypress/support/* that had defined a text command? Can you share the code from the files within cypress/support/*?

You have typo in selector, thats why Cypress can not get it:

:mth-child

Suppose it should be nth-child. Please note that you have 2 places with this typo.
Feel free to debug it by click on get command in log and check in Chrome console what it yields.

thanks @jennifer-shehane , strange, text() was working before , didn't had anything in cypress/support/* for text().
Nevertheless I got it working with .invoke('text') .
@Shelex, :mth-child was a typo I made when drafting my post question(corrected above now), in my code it was always nth-child.

I think there has been an api deprecation...cy.navigateByUrl stopped working for me and I cannot seem to find any references to it anywhere via Google. Using cy.visit now.

Was this page helpful?
0 / 5 - 0 ratings