如何与iframe内部的元素进行交互。但是iframe在柏树中的两个阴影dom&#
我无法与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()
})
I am unable to interact with elements inside shadow DOM and iframe. Attached is the HTML document snippet. I am using cypress here. I am directly interacting with the second shadow DOM and then the iframe.
My cypress code
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()
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的柏树配置文件中,添加
includeShadowdom:true
,这将确保所有柏树命令都将自动遍历Shadow doms。对于iframe的我,我建议您使用插件 cypress-frame-iframe plugin。
In your cypress config file, add
includeShadowDom: true
, this will make sure that all the cypress commands will automatically traverse Shadow DOMS.For iFrame's I owuld suggest you use the plugin cypress-iframe plugin.
使用柏树命令,以下可能是您的测试。
首先,
.notification-toast
是一个toat弹出窗口,它将是动画的,因此在其下方包括.layout-wrapper
,柏树将等待动画完成。Using Cypress commands, the following could be your test.
First,
.notification-toast
is a toat popup, which will be animated so include the.layout-wrapper
below it and Cypress will wait for animation to finish.