【问题标题】:Unable to switch to Iframe in Gmail using Selenium webdriver Java无法使用 Selenium webdriver Java 在 Gmail 中切换到 iframe
【发布时间】:2023-03-08 18:17:01
【问题描述】:

这是针对注入Gmailiframe,我无法切换到此框架,非常感谢任何帮助。

HTML 代码:

<iframe src="chrome-extension://fcinnggknmdfkilogcndkgpojpfojeem/src/iframe.html" id="Hiver_iframe_content" style="width: 100%; height: 263px; position: absolute; top: 60px; z-index: 4; border: none; display: none;"></iframe>

我想做什么:

driver.switchTo().frame("Hiver_iframe_content");

几天前工作得很好..!!

【问题讨论】:

  • 您能否考虑详细说明for an iframe injected into Gmail 的意思?谢谢
  • Hiver 是一个 Gmail 扩展程序,其中的功能在 Gmail 中作为 iframe 工作
  • 太棒了!!!你能考虑向我们展示你的作品吗?谢谢
  • 您好,您可以在 hiverhq.com 试用我们的产品

标签: java selenium google-chrome-extension webdriver gmail


【解决方案1】:

这不是你正在尝试的切换框架的方式

driver.switchTo().frame("Hiver_iframe_content");

你必须在切换时传递 webElement 或框架索引

试试这个,让我知道

driver.switchTo().frame(driver.findElement(By.id("Hiver_iframe_content")));

driver.switchTo().frame(0);  // 0 is index of frame

【讨论】:

  • 谢谢我以前试过,现在也试过了,我明白了:NoSuchFrameException: no such frame: element is not a frame
  • 不工作我得到一个错误:NoSuchFrameException:没有这样的框架:元素不是框架
  • 我试过下面的 driver.switchTo().defaultContent(); WebDriverWait 等待=新 WebDriverWait(驱动程序, 90); wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("Hiver_iframe_content")); driver.switchTo().frame(driver.findElement(By.id("Hiver_iframe_content")));这些都不起作用
  • 这是特定于在 Gmail 中加载的 iframe
  • 不,以防硒被混淆:)
【解决方案2】:

您可以使用下面给出的显式等待来等待帧加载。

WebDriverWait 等待=新 WebDriverWait(驱动程序, 90); wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("Hiver_iframe_conten"));

试着告诉我。

谢谢, 穆尔蒂。 S

【讨论】:

  • 感谢您的回复,它不起作用 :( 好像 gmail 改变了 iframe 在其中加载的方式
【解决方案3】:

尝试使用切换到框架 WebElement 如下:

 driver.switchTo().frame(driver.findElement(By.cssSelector("iframe#Hiver_iframe_content")));

【讨论】:

    【解决方案4】:

    似乎随着 Gmail 新登录的发布,谷歌发布了新版本的 chrome 驱动程序,我通过升级我的 chromedriver 版本解决了我的问题

    【讨论】:

      【解决方案5】:

      我找到了一种切换到您提到的 iframe 的方法。事实上,不是一个 iframe,而是两个 iframe,你必须切换。看下面的代码:

      driver.switchTo().defaultContent();//First switch to default content
      driver.switchTo().frame("Hiver_iframe_content");//Switch to 1st iframe
      driver.switchTo().frame("iframe_handler");//Switch to 2nd iframe 
      

      P.s-此代码现在适用于我们的自动化,我们可以从 iframe 本身访问 v2 :-)

      【讨论】:

        猜你喜欢
        • 2017-05-06
        • 1970-01-01
        • 2017-12-24
        • 1970-01-01
        • 2018-12-31
        • 2016-01-15
        • 2012-08-05
        • 2021-06-19
        • 1970-01-01
        相关资源
        最近更新 更多