【问题标题】:Protractor iframe element is not found / not visible量角器 iframe 元素未找到/不可见
【发布时间】:2016-10-06 04:07:01
【问题描述】:

我正在使用 Protractor 编写一个 e2e 测试,该测试需要访问 Angular 2 应用程序中的 iframe 元素。

我相信我已经成功切换到 iframe,但由于某种原因,我希望选择的元素在我的测试“没有找到带有 css id 选择器的元素......”或“元素不是可见。”

这是我的代码:

this.fillOutInfo = function(input){

 this.selectBox.click().then(function(){
    browser.switchTo().frame(this.selectBox)
     .then(function(){
        browser.findeElement(by.id('recurly-hosted-input-field')).sendKeys(input)
        .then(function(){
            browser.switchTo().defaultContent();
            })
         })
      })
   } //selectBox references the iframe element within the DOM

当我检查元素时,上面的 id 显然在代码中,但由于某种原因它没有被访问。我的功能执行不正确吗?我已经尝试了不同的方法来查找我需要的输入,例如嵌套定位器,但没有任何效果。

非常感谢任何帮助!

【问题讨论】:

  • 在嵌套的then 中有你的console.log 吗?你如何在量角器中解决promise?
  • 你提到了browser.findeElement。是错字吗?
  • @SudharsanSelvaraj 是的,抱歉,这是 stackoverflow 上的错字,而不是实际代码

标签: javascript angularjs iframe protractor


【解决方案1】:

如果不是 sudharsan selvaraj 指出的拼写错误,请尝试

element.all(by.id('recurly-hosted-input-field')).count().then(function(count) {
console.log("Number of elements with same id: " + count);});

这会让你知道有多少元素具有相同的 id。这也发生在我身上,因为我正在使用具有相同定位器属性的错误元素。

希望对你有帮助

【讨论】:

  • 感谢您的回复。前面我应该提到,有多个 iframe,但在每个 iframe 中,只有一个带有上述 id 的标签。我知道我选择了正确的 iframe,因为在第一行我首先点击它。
【解决方案2】:

经过更多的研究和实验,我找到了一个适合我的解决方案。这里是:

 this.fillOutInfo = function(input){

 this.selectBox.click().then(function(){
    browser.ignoreSynchronization = true;
    browser.switchTo().frame(0)
     .then(function(){
        element(by.id('recurly-hosted-input-field')).sendKeys(input)
        .then(function(){
            browser.switchTo().defaultContent();
            })
         })
      })
   }

我认为这两件事是:1.) 添加 ignoreSynchronization 和 2.) 基于索引而不是定位器切换帧上下文。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-30
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多