赛普拉斯-在iframe中获取元素

时间:2019-08-23 06:41:38

标签: automation automated-tests cypress

我解决了使用iframe的问题,但现在我无法获取元素。也许我发现情况很糟,但是现在花了我太多时间,接下来我不做什么。

源代码:

<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>

输入图片:

我的get函数:

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

谢谢大家的帮助。

1 个答案:

答案 0 :(得分:1)

不幸的是,赛普拉斯在与iframe交互方面存在一些未解决的问题。但这是一个非常简单的解决方法:https://github.com/cypress-io/cypress/issues/136#issuecomment-328100955

无论如何,由于同源性的限制,我相信只有在外部页面和iframe的域相同的情况下,此方法才能起作用。