【问题标题】:webdriverIO 5, how to switch to iframe when its element 'id' not given?webdriverIO 5,未给出元素“id”时如何切换到iframe?
【发布时间】:2019-02-21 04:52:22
【问题描述】:
frame html code:
<iframe title="frame report" class="ReportViewer__iframe" src="/yesyyy.aspx?reportId=145&amp;ts=1550681978158&amp;bgcolor=#f8f9fb" width="100%" height="100%"></iframe>

标题和类名定位器的脚本都失败了——'ERROR webdriver: Request failed due to Error: no such frame'

【问题讨论】:

  • 用你的代码试验更新问题
  • 这是 html 中的第一个 iframe,并且没有 id 标签。使用 title xpath 和 .ReportViewer__iframe 定位器会出现:ERROR webdriver: Request failed due to Error: no such frame'

标签: selenium-webdriver webdriver-io


【解决方案1】:

使用以下代码。

        driver.switchTo().defaultContent();
        WebElement frameXpath = driver.findElement(By.xpath("//iframe[@title='frame report']"));
        driver.switchTo().frame(frameXpath);

【讨论】:

  • 感谢您的回答,但这不是预期的解决方案,我想将上下文带到 iframe(代码中的第一个),在 xpath - title 或 class .ReportViewer__iframe 选择器中切换失败。
  • 使用 driver.switchTo().frame(frameXpath); 时,上下文将切换到 iframe命令。这个 xpath 对我有用的 iframe。
  • WebDriverIO 有驱动关键字吗?
【解决方案2】:

得到解决方案,需要通过可用的 loators(标题和 css 类)传递 iframe 的对象 browser.switchtoframe($('.report__iframe'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 1970-01-01
    • 2021-11-05
    相关资源
    最近更新 更多