3

I have the following problem. I want to write a function that can be used to check whether the search button is deactivated or not. If the search button is deactivated, then carry out the next steps - fill out the search fields and click on the "Start search" button, and if the search button is activated, then first click on the button so that the search fields are displayed and then do the next steps - fill out the search fields and click on the button "Start search". I've tried all sorts of things, but unfortunately without success.

I would look forward to any help.

button is disabled

button is enabled

<button id="mainbody:searchPersRecord:searchIcon" name="mainbody:searchPersRecord:searchIcon" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only btNormal showHeadArea ui-state-disabled" alt="Open search" title="Open search" onclick="showHeadArea(true); tryFocusComponentInAnyForm('searchHeadField1_Surname'); return false;;window.open('\/matrix\/views\/basis\/personalmanagement\/searchPersRecord.jsf','_self')" role="button" aria-disabled="false" disabled="disabled"><span class="ui-button-icon-left ui-icon ui-c ma-icon ma-search"></span><span class="ui-button-text ui-c">ui-button</span></button>


<button id="mainbody:searchPersRecordDivisionForm:searchIcon" name="mainbody:searchPersRecordDivisionForm:searchIcon" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only btNormal showHeadArea" alt="Open search" title="Open search" onclick="showHeadArea(true); tryFocusComponentInAnyForm('number'); return false;;window.open('\/matrix\/views\/basis\/personalmanagement\/searchDivision.jsf','_self')" role="button" aria-disabled="false"><span class="ui-button-icon-left ui-icon ui-c ma-icon ma-search"></span><span class="ui-button-text ui-c">ui-button</span></button>
Kamen K.
  • 31
  • 1
  • 1
  • 4

1 Answers1

4
    cy.get('your_button').then(($button) => {
        if(cy.get($button).should('not.be.disabled')){
            //your logical code for button ACTIVE
        }
        else{
            //your logical code for button NOT ACTIVE
        }
    })
Gustavo
  • 41
  • 2
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value – nima Sep 28 '21 at 08:15
  • 1
    Maybe I'm missing something, but I can't see this working: you are introducing an assertion, so the test will fail as soon as it's not met. Timed out retrying after 4000ms: expected '' to be 'disabled' – Baronvonbirra Sep 06 '22 at 08:54