【问题标题】:Cypress element is not visible because it has an effective width and height of 0 x 0 pixelsCypress 元素不可见,因为它的有效宽度和高度为 0 x 0 像素
【发布时间】:2021-07-09 15:41:17
【问题描述】:

对 iframe 中的元素执行操作时出现以下错误:

"60000 毫秒后重试超时:预期 '

' 为'可见' 这个元素

不可见,因为它的有效宽度和高度为:0 x 0 像素。"

这是我的元素代码:

cy.get('iframeselector',{timeout: 150000})
    .its('0.contentDocument.body').should('not.be.empty')
    .then(cy.wrap).find('p').should('be.visible').clear().type('abc')

我尝试过使用 {force:true} 甚至通过调用方法更改宽度。但到目前为止,没有什么对我有用。任何帮助将不胜感激。

下面是 html 的截图:

【问题讨论】:

  • 我什至经历过 github.com/cypress-io/cypress/issues/2000github.com/cypress-io/cypress/issues/695 但到目前为止对我没有任何帮助
  • 你能创建一个小的可重复的示例 repo 并与我们分享吗?
  • "甚至通过调用方法改变宽度" 你必须同时改变宽度和高度。
  • @Manuel Abascal 在问题中添加了 html snap
  • @Ouroborus 调用方法没有改变宽度。调用函数调用前后的宽度保持不变。

标签: javascript jquery automation cypress


【解决方案1】:

我得到了解决方案。页面中还有 3 个其他 iframe,每个 iframe 都在一个容器内。我打算对第二个 iframe 中的元素执行操作,默认情况下我的代码正在尝试处理第一个 iframe 中的元素。

Cyress 没有给出关于找到多个 iframe 的错误。所以它让我因 0x0 像素错误而大吃一惊。以下对我有用:

  cy.get('parentContainer').within(()=>{
        cy.get('iframeselector',{timeout: 150000})
        .its('0.contentDocument.body').should('not.be.empty')
        .then(cy.wrap).find('p').should('be.visible').clear().type('abc')
})

【讨论】:

    猜你喜欢
    • 2016-07-17
    • 2018-08-03
    • 1970-01-01
    • 2021-12-07
    • 2020-03-11
    • 1970-01-01
    • 2014-01-24
    • 2014-09-24
    • 2017-02-14
    相关资源
    最近更新 更多