【问题标题】:Search for button in iframe在 iframe 中搜索按钮
【发布时间】:2020-05-12 22:21:00
【问题描述】:

我的应用程序在同一个屏幕中有多个 iframe。这些 iframe 在每个会话中都有不同的名称,因此我想在应用程序中搜索其中一个名为“Personal”的 iframe 中的按钮。应保存此 iframe-name 以在其他方法中使用。有人知道怎么做吗?

【问题讨论】:

  • 你使用某种网络框架吗?或者你用什么来显示 iframe?
  • 它是 Pega 中的一个屏幕。我还没有构建应用程序,只是试图自动化一些测试
  • 你能告诉我们一些代码和你已经尝试过的吗?
  • @Menno:您能否提供更多信息?您是否为此使用了 HTML 规则?
  • 请关闭/删除该主题,因为我已经找到了解决方案:

标签: java loops iframe pega


【解决方案1】:

请关闭/删除此主题,因为我找到了解决方案:

public WebElement findElement(By locator) {
    driver.switchTo().defaultContent();
    //list all iframes
    List<WebElement> iframeList = driver.findElements(By.tagName(("iframe")));
    final List<WebElement> foundElements = new ArrayList<>();
    iframeList.forEach(iframe -> {

        driver.switchTo().frame(iframe);
        List<WebElement> foundElementList = driver.findElements(locator);
        if (foundElementList.size() > 0) {
            foundElements.addAll(foundElementList);
        } else driver.switchTo().defaultContent();
    });
    return foundElements.get(0);
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-07
  • 1970-01-01
  • 2016-05-26
  • 2022-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多