【问题标题】:How does selenide find the element inside the document and IFrameselenide如何找到文档和IFrame里面的元素
【发布时间】:2021-10-07 11:44:39
【问题描述】:

寻找在使用 ReactJs 呈现的文档中选择带有 Selenide 元素的方法。

我需要访问文档和 Iframe 中的 xpath //h1/span[text()=' 1']。有没有办法获取该元素并切换回主窗口?

页面内容如下所示(由于太长,两张图片中的页面内容相同):

【问题讨论】:

    标签: automated-tests selenide


    【解决方案1】:

    要切换回主窗口,您可以执行以下操作:

          switchTo().parentFrame();
    

    这将使您退出 iFrame 上下文并返回主站点(或父页面)。

    关于超时问题,我认为这里已经介绍过:https://stackoverflow.com/a/60167733/9350566

    【讨论】:

      【解决方案2】:

      我可以使用下面的方法成功,但我有时会得到 TimeoutException。

      [1627896042.179][SEVERE]: Timed out receiving message from renderer: 30.000

       public WebDriver getFrame(){
          try {
              return Wait().until(frameToBeAvailableAndSwitchToIt(iFramePth));
          }catch (Exception ex){
              System.out.println("error in get Frame");
              ex.printStackTrace();
              return null;
          }
      }
      

      为此,我在调用上述方法之前使用了以下方法。 (检查 iframe 是否可用)

      iFramePthElement.should(Condition.appear, Duration.ofSeconds(TIME_OUT));
      

      但即使现在它有时也会失败。
      [1627896042.179][SEVERE]: Timed out receiving message from renderer: 30.000

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-09-21
        • 2019-05-25
        • 2018-11-05
        • 2017-07-12
        • 2016-08-09
        • 1970-01-01
        • 2021-10-13
        相关资源
        最近更新 更多