【问题标题】:How to get total number of nested frames inside the frame如何获取框架内嵌套框架的总数
【发布时间】:2020-10-24 10:19:15
【问题描述】:

带有 3 个嵌套帧的 Frame_top 快照:

代码:

WebElement topframe = driver.findElement(By.xpath("//frame[@name='frame-top']"));   
String frame1 =  driver.switchTo().frame(topframe).switchTo().frame("frame-left").findElement(By.xpath("//body")).getText();                
System.out.println(frame1);
List<WebElement> nestedFrames = driver.switchTo().frame(topframe).findElements(By.tagName("frame"));
System.out.println(nestedFrames.size());

在顶部,您可以看到此页面在框架内有嵌套框架(frame_top)。
使用第 1-3 行,我可以获得每个嵌套框架的文本。但是我无法获得“Frame_top”内的帧数。(第 4-5 行)。
如何获得“frame_top”内的总帧数? 提前致谢

【问题讨论】:

    标签: selenium nested webdriverwait frames expected-condition


    【解决方案1】:

    要获取父级&lt;frame&gt; 中嵌套 的总数,您需要:

    • 为所需的 frameToBeAvailableAndSwitchToIt 诱导 WebDriverWait
    • framesvisibilityOfAllElementsLocatedBy() 引入 WebDriverWait
    • 您可以使用以下任一Locator Strategies
      • 使用 cssSelectortagName

        new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("frame[name='frame-top']")));
        System.out.println(new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.tagName("frame"))).size());
        
      • 使用 xpathtagName

        new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//frame[@name='frame-top']")));
        System.out.println(new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.tagName("frame"))).size());
        

    参考

    您可以在以下位置找到一些相关讨论:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      • 2021-12-17
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多