为什么框架的 return 类型是 Selenium 中的 WebDriver?
Why the return type for frames is WebDriver in Selenium?
为什么框架的 return 类型是 Selenium 中的 Web 驱动程序。
考虑以下驱动程序切换到框架的代码。但是为什么 return 类型是以下代码的 Web 驱动程序。
driver.switchTo().frame(int/string/webelement);
因为驱动程序与当前焦点文档(页面)的元素交互,而 iframe 是嵌入另一个文档(例如网页)的独立文档。
因此,为了与 iframe 的元素交互,我们需要关注那个特定的框架,这就是为什么 returns 当前关注的 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
*/
为什么框架的 return 类型是 Selenium 中的 Web 驱动程序。 考虑以下驱动程序切换到框架的代码。但是为什么 return 类型是以下代码的 Web 驱动程序。
driver.switchTo().frame(int/string/webelement);
因为驱动程序与当前焦点文档(页面)的元素交互,而 iframe 是嵌入另一个文档(例如网页)的独立文档。
因此,为了与 iframe 的元素交互,我们需要关注那个特定的框架,这就是为什么 returns 当前关注的 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 */