【问题标题】:Detecting Whether An Iframe Is Angular Or Not With Protractor使用量角器检测 iframe 是否有角度
【发布时间】:2017-05-29 12:18:09
【问题描述】:

我有以下不寻常的用例。我在下面详细说明

1) 我在一个有角度的页面上,我在页面上做了一些操作[它加载了一个非角度的 iFrame]

2) 我切换到非角度 iframe 并与一些屏幕进行交互。

3) 最终这会导致重定向发生回一个角度页面。

当我在第 2 步中使用量角器时,我必须将其与 flag browser.ignoreSynchronization 设置为 false 一起使用,因为它是非角度的。我需要一种方法来检查我正在与之交互的 form 是否有角度,以帮助从步骤 2) 到 3) 的平稳过渡。

我知道您可以使用

在页面上自动检查角度功能

browser.executeAsyncScript 或 browser.executeScript 以及

!!window.angular (角度 v1)

!!window.getAllAngularTestabilities(角度 v2)

但这在这个用例中不起作用,因为无论您是否与非角度 iframe 交互,所有这些都将返回 true。有人有任何其他可能适用于这样的用例的建议吗?非常感谢。

【问题讨论】:

    标签: javascript angularjs iframe protractor


    【解决方案1】:

    当我需要自动化 iframe 时,我通常会执行以下操作

    // 1) When you know the iframe is there
    browser.switchTo().frame(0);
    
    // 2 a) You don't need to disable the wait for anguler, just use vanila webdriver, it will work on both
    browser.driver.findElement(by.css('.your-css-selector'));
    // Do some more interaction
    browser.driver.findElement(by.css('.input-css-selector')).sendKeys('type something');
    browser.driver.findElement(by.css('.button-css-selector')).click());
    
    // 2b) Or now just use the Protractor syntax, 
    //     because you switched you should be able to use it now.
    
    // 3) Switch back
    browser.switchTo().defaultContent();
    
    // 4) Check for example with Protractor expectedConditions if the iframe is gone
    var EC = protractor.ExpectedConditions;
    // Waits for the ifram to be no longer present on the dom.
    browser.wait(EC.stalenessOf($('iframe')), 5000);

    如您所见,无需这样做browser.ignoreSynchronization = true;

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-07
      • 2017-03-13
      • 1970-01-01
      相关资源
      最近更新 更多