Home > Software engineering >  Cypress clicking on a button with href"..." does not return information that it should
Cypress clicking on a button with href"..." does not return information that it should

Time:11-03

I am working with react app and have a href button that supposed to take me the new url but also load some information for a dropdown on the next page. below is the button code

 <a class="MuiButtonBase-root MuiButton-root MuiButton-text jss1069 depth-2 jss1073" tabindex="0" role="button" aria-disabled="false" href="...." aria-current="page">
    <span class="MuiButton-label">Programs</span>
   <span class="MuiTouchRipple-root">
    <span class="MuiTouchRipple-ripple MuiTouchRipple-rippleVisible" style="width: 276.159px; height: 276.159px; top: -126.08px; left: -69.0797px;"></span></span></a>

My cypress code i tried to click on it.

cy.get('button[style="padding-left: 40px;"]',{timeout: 10000})
            .should('be.visible')
            .click()
              
cy.get('a[href="......"]')
.should('be.visible')
.click()

i tried getting it with href ,with contains, timing out visible and etc. it does click on it but then API call behind it does not load info i need and show errors on Cypress runner even tho it returned 200. This is runner screen in yellow shows that weird error and consol says "you need a javascript to run this app". I have js enabled aswell on browser. Runner screen

Any input is highly appreciated

CodePudding user response:

I could see that your application is generating exceptions. To handle exceptions you can add this after the click.

Cypress.on('uncaught:exception', (err, runnable) => {
  return false
})
  • Related