cypress如何在iframe中定位元素

cypress如何在iframe中定位元素,iframe,cypress,Iframe,Cypress,在cy.wrap($doc.find(#input)).type(“test”,{force:true})下它不起作用。:CypressError:超时重试:应查找元素:“undefined”,但从未找到它 it('iframe - check it', function () { cy.visit("https://jsfiddle.net/1w9jpnxo/1/"); cy.get("iframe[name='result']").then($iframe => {

cy.wrap($doc.find(#input)).type(“test”,{force:true})下它不起作用。:CypressError:超时重试:应查找元素:“undefined”,但从未找到它

it('iframe - check it', function () {
    cy.visit("https://jsfiddle.net/1w9jpnxo/1/");
    cy.get("iframe[name='result']").then($iframe => {

        const $doc = $iframe.contents();
        cy.wrap($doc.find("#input")).type("test", { force: true });
        //cy.wrap($doc.find("#submit")).click({ force: true });
    });
})
“柏树”:“^3.8.3”

以上是互联网上的常见做法,但对我来说并不适用


我还通读了上的开放式提案,但无法理解解决方案是什么。

在向
cypress/support/commands.js添加助手函数后,如我在此处的回答()中所述,您可以评估输入是否存在:

cy.get(“#iframe id”)
.iframe('body#yourInputId'))
.should('存在')
我不确定输入是否有效,但您肯定可以尝试:

cy.get(“#iframe id”)
.iframe('body#yourInputId'))
.type('测试文本')

让我知道它是否有效,我自己也很好奇。

你可以检查我在这个问题上的答案()。Cypress中的iframe很棘手,但有一个变通方法可以帮助我评估iframe中元素的可见性。不确定它是否也适用于与元素交互,但您可以试试。@DurkoMatko感谢!您能分享一下代码吗?您是如何在iframe中定位元素的?我现在不能尝试你的解决方案,但我不能等待。再次感谢!