【问题标题】:How to access the nested html which is within a frame through Selenium [duplicate]如何通过 Selenium 访问框架内的嵌套 html [重复]
【发布时间】:2019-01-19 18:03:45
【问题描述】:

我有一个网站,其中嵌套了一个 html 标签,如下所示。 问题:

  1. 如何使用 selenium 在 frameBody 中搜索元素?
  2. 如何等待frameBody中的元素成功加载?

请帮忙。谢谢。 请从link获取应用程序源代码。

【问题讨论】:

  • 我试过这个 driver.switchTo().frame("frameBody");但它会导致 No frame element found by name or id frameBody.

标签: java html selenium webdriver webdriverwait


【解决方案1】:

<frame>id = frameBody嵌套在​​另一个<iframe>中,需要先切换到它

WebElement iframe = driver.findElement(By.cssSelector("#tabFrames > iframe:nth-child(1)"));
driver.switchTo().frame(iframe);
driver.switchTo().frame("frameBody");

【讨论】:

  • 请看我的代码截图。你能指出我的确切结构吗?
  • @peterwkc 结构很清晰,可以通过缩进看到。您也可以在开发者工具中打开和关闭部分来查看它。
  • 它抛出 NoSuchElementException: no such element: Unable to locate element: tabFrames > iframe:nth-child(2)
  • @peterwkc 应该是driver.findElement(By.cssSelector("#tabFrames > iframe:nth-child(1)"));
  • 我正在使用 xpath,它可以工作。
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-30
  • 2021-07-18
  • 2020-10-24
相关资源
最近更新 更多