【问题标题】:Why the return type for frames is WebDriver in Selenium?为什么框架的返回类型是 Selenium 中的 WebDriver?
【发布时间】:2018-06-27 05:51:47
【问题描述】:

为什么框架的返回类型是 Selenium 中的 Web Driver。 考虑下面的代码,驱动程序切换到框架。但是为什么下面代码的返回类型是 Web Driver。

driver.switchTo().frame(int/string/webelement);

【问题讨论】:

    标签: selenium-webdriver iframe frames


    【解决方案1】:

    因为驱动程序与当前关注的文档(页面)的元素进行交互,而 iframe 是嵌入在另一个文档(例如网页)中的单独文档。

    所以要与 iframe 的元素交互,我们需要关注特定的框架,这就是它返回当前关注的 webdriver 实例的原因。

    参考 selenium 文档:WebDriver 接口

    WebDriver frame(int index);
    
    /**
     * Select a frame by its name or ID. Frames located by matching name attributes are always given
     * precedence over those matched by ID.
     *
     * @param nameOrId the name of the frame window, the id of the <frame> or <iframe>
     *        element, or the (zero-based) index
     * @return This driver focused on the given frame
     * @throws NoSuchFrameException If the frame cannot be found
     */
    

    【讨论】:

    • 能否分享一下 selenium 文档,我无法访问您附加的文档。
    • 嘿@Aditya,在selenium 库中,有一个包名为org.openqa.selenium;,还有一个类名WebDriver.class。你可以在那里找到上面提到的代码。要打开类文件,只需控制+单击代码中的WebDriver,如WebDriver driver = somedriver
    猜你喜欢
    • 1970-01-01
    • 2019-06-24
    • 2022-11-03
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多