首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获得帧内嵌套帧的总数

如何获得帧内嵌套帧的总数
EN

Stack Overflow用户
提问于 2020-07-03 16:52:16
回答 1查看 590关注 0票数 1

包含3个嵌套框架的Frame_top快照:

代码:

代码语言:javascript
复制
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“中的帧总数?提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-05 17:48:48

要获得父<frame>中嵌套帧的总数,您需要:

对于所需的帧的frameToBeAvailableAndSwitchToIt.

  • Induce (),
  • 为visibilityOfAllElementsLocatedBy()诱导WebDriverWait。
  • 您可以使用以下的Locator Strategies之一:使用cssSelector和tagName的

新WebDriverWait(驱动程序,新WebDriverWait(驱动程序,10).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.tagName("frame"))).size()); )

10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//frame@name='frame-top'")));System.out.println(驱动程序,新WebDriverWait(驱动程序,10).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.tagName("frame"))).size());))

参考文献

您可以在以下几个方面找到相关的讨论:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62719676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档