[英]Web app can't read it's own DOM elements when in an iframe. Works fine outside of iframe
[英]How to interact with the elements inside iframe. But iframe is within two shadow DOM's in cypress
我無法與 shadow DOM 和 iframe 中的元素進行交互。 隨附的是 HTML 文檔片段。 我在這里使用柏樹。 我直接與第二個影子 DOM 交互,然后是 iframe。
我的柏樹代碼
cy.get('formbuilder-mainpage').should(e => {
console.log(e)
const [dom] = e.get()
console.log(dom)
dom.shadowRoot.querySelector().getIframe('iframe').find('New Organization').click()
})
在您的 cypress 配置文件中,添加includeShadowDom: true
,這將確保所有 cypress 命令將自動遍歷 Shadow DOMS。
對於 iFrame,我建議您使用插件cypress-iframe插件。
cy.iframe('iframe').('elmeent-selector').click()
使用賽普拉斯命令,以下可能是您的測試。
首先, .notification-toast
是一個 toat 彈出窗口,它將被動畫化,因此在其下方包含.layout-wrapper
,賽普拉斯將等待 animation 完成。
it('test deeply nested shadow DOM', () => {
cy.get('main .notification-toast .layout-wrapper')
.shadow() // 1st shadow
.find('formbuilder-mainpage')
.shadow() // 2nd shadow
.getIframe('iframe')
.find('New Organization')
.click()
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.