无法获得位于柏树iframe中的元素

时间:2020-06-02 09:22:57

标签: cypress

我正在使用此代码 我已经使用了每个属性,但没有找到

my html code pic

cy.get('.gjs-frame')
.then(($iframe) => {
  const $body = $iframe.contents().find('body')
   cy.wrap($body)
   //cy.get('#v-app')
    //cy.get('.layout')
    //cy.get('.gjs-hovered')
    //.get('.v-application--wrap [data-gjs-type="wrapper"]')
   // .get('[data-gjs-type="wrapper"]')
    //.get('#v-app .v-application--wrap')
    //.get('.v-application--wrap')
   // .get('#v-mount').should('be.exist')

})

1 个答案:

答案 0 :(得分:1)

引用:Working with iframes in Cypress

const getIframeDocument = () => {
  return cy.get('iframe').its('0.contentDocument').should('exist')
};

const getIframeBody = () => {
  // get the document
  return getIframeDocument()
    .its('body').should('not.be.undefined')
    .then(cy.wrap);
}

getIframeBody().find(<selector>).should('contain', <content>);