Dominik Skála
Dominik Skála

Reputation: 831

Cypress - get an element in iframe

I solve the problem with getting into iframe but now I can't get my element. Maybe I'm finding bad but right now it took me too much time and I don't what to do next.

Source code:

<divid="ctl00_Telo_Dock_1005_C_ctl00_MainPage1_myPageVozidlo_inpDruhVozidla_ADX" class="inputCell" style="visibility:visible;display:inherit;">
  <span id="ctl00_Telo_Dock_1005_C_ctl00_MainPage1_myPageVozidlo_lblDruhVozidla_ADX" class="labels labelC1_n W270">Druh vozidla:
  </span>
    <div id="ctl00_Telo_Dock_1005_C_ctl00_MainPage1_myPageVozidlo_cmbDruhVozidla_ADX" tabindex="13" class="RadDropDownList RadDropDownList_CMS_Black RadComboBoxInput" style="width:216px;height:23px;font-weight:bold;font-size:10pt;font-family:Arial;color:#396170;border-width:1px;border-style:Solid;border-color:#FDC267;background-color:#F9FBFC;">
      <span class="rddlInner">
        <span class="rddlFakeInput"></span>
        <span class="rddlIcon"><!-- &nbsp; --></span>
      </span>
      <div class="rddlSlide" id="ctl00_Telo_Dock_1005_C_ctl00_MainPage1_myPageVozidlo_cmbDruhVozidla_ADX_DropDown" style="display:none;">
        <div class="rddlPopup rddlPopup_CMS_Black">
          <ul class="rddlList">
            <li class="rddlItem  rddlItemSelected"></li>
            <li class="rddlItem">Osobní automobily</li>
            <li class="rddlItem">Motocykly</li>
            <li class="rddlItem">Užitkové automobily</li>
          </ul>
        </div>
      </div>
      <input id="ctl00_Telo_Dock_1005_C_ctl00_MainPage1_myPageVozidlo_cmbDruhVozidla_ADX_ClientState" name="ctl00_Telo_Dock_1005_C_ctl00_MainPage1_myPageVozidlo_cmbDruhVozidla_ADX_ClientState" type="hidden" />
    </div>
</div>

Image of input:

My get function:

cy.get('#iframe-id')
  .iframe('body #elementToFind')
  .should('exist')

Thank you all for helping me.

Upvotes: 2

Views: 15414

Answers (1)

Arnon Axelrod
Arnon Axelrod

Reputation: 1672

Unfortunately, Cypress have some open issues regarding interacting with an iframe. But here's a pretty straightforward workaround: https://github.com/cypress-io/cypress/issues/136#issuecomment-328100955.

Anyway, I believe that this can work only if the domain of the outer page and of the iframe are the same, due to the same-origin limitation.

Upvotes: 2

Related Questions