- WebdriverIO 教程
- WebdriverIO - 首页
- WebdriverIO - 简介
- WebdriverIO - 前提条件
- WebdriverIO - 架构
- WebdriverIO - NodeJS入门
- WebdriverIO - NPM安装
- WebdriverIO - VS Code安装
- WebdriverIO - package.json
- WebdriverIO - Mocha安装
- Selenium 独立服务器安装
- WebdriverIO - 配置文件生成
- WebdriverIO - VS Code智能提示
- WebdriverIO - wdio.conf.js 文件
- WebdriverIO - XPath 定位器
- WebdriverIO - CSS 定位器
- WebdriverIO - Link Text 定位器
- WebdriverIO - ID 定位器
- WebdriverIO - 标签名定位器
- WebdriverIO - 类名定位器
- WebdriverIO - name 属性定位器
- 断言的 Expect 语句
- WebdriverIO - 正常流程
- WebdriverIO - 常用浏览器命令
- WebdriverIO - 浏览器窗口大小处理
- WebdriverIO - 浏览器导航命令
- 处理复选框和下拉菜单
- WebdriverIO - 鼠标操作
- 处理子窗口/弹出窗口
- WebdriverIO - 隐藏元素
- WebdriverIO - frame框架
- WebdriverIO - 拖放操作
- WebdriverIO - 双击操作
- WebdriverIO - Cookies
- WebdriverIO - 处理单选按钮
- webelement 的 Chai 断言
- WebdriverIO - 多个窗口/标签页
- WebdriverIO - 滚动操作
- WebdriverIO - 警报框
- WebdriverIO - 代码调试
- WebdriverIO - 截取屏幕截图
- WebdriverIO - JavaScript 执行器
- WebdriverIO - 等待
- WebdriverIO - 并行运行测试
- WebdriverIO - 数据驱动测试
- 从命令行参数运行测试
- 使用 Mocha 选项执行测试
- 使用 Allure 生成 HTML 报告
- WebdriverIO 有用资源
- WebdriverIO - 快速指南
- WebdriverIO - 有用资源
- WebdriverIO - 讨论
WebdriverIO - frame框架
HTML 代码中的 frame 框架由 frames/iframe 标签表示。WebdriverIO 可以通过从主页面切换到 frame 框架来处理 frame 框架。
frame 框架的方法
一些与 frame 框架一起使用的方法如下:
browser.switchToFrame('<frame id/index/locator>')
此方法用于将焦点从主页面切换到 frame 框架。frame 框架的 ID、索引或定位器作为参数传递给此方法。
语法
语法如下:
browser.switchToWindow(x)
要将焦点从 frame 框架切换到主页面,我们必须将 null 作为参数传递给 browser.switchToFrame 方法。
让我们看看 frame 框架内元素的 HTML 代码,并获取其中的文本 - BOTTOM。
上图中高亮的标签名为 frame,其 name 属性的值为 frame-bottom。
首先,请按照“使用 WebdriverIO 的正常流程”一章中的步骤 1 到步骤 5 进行操作,步骤如下:
步骤 1 - 安装 NodeJS。有关如何执行此安装的详细信息,请参阅“使用 NodeJS 入门”一章。
步骤 2 - 安装 NPM。有关如何执行此安装的详细信息,请参阅“NPM 安装”一章。
步骤 3 - 安装 VS Code。有关如何执行此安装的详细信息,请参阅“VS Code 安装”一章。
步骤 4 - 创建配置文件。有关如何执行此安装的详细信息,请参阅“配置文件生成”一章。
步骤 5 - 创建规范文件。有关如何执行此安装的详细信息,请参阅“Mocha 安装”一章。
步骤 6 - 将以下代码添加到创建的 Mocha 规范文件中。
// test suite name
describe('Tutorialspoint application', function(){
//test case
it('Frames', function(){
// launch url
browser.url('https://the-internet.herokuapp.com/nested_frames')
//switch to frame
browser.switchToFrame($("frame[name='frame-bottom']"))
//identify element with tagname
const p = $('<body>')
//get text inside frame
console.log(p.getText() + ' - Text inside frame')
//switch to main page
browser.switchToFrame(null)
});
});
运行配置文件 - wdio.conf.js 文件,命令为:
npx wdio run wdio.conf.js
有关如何创建配置文件的详细信息,请参阅“wdio.conf.js 文件”和“配置文件生成”章节。
您的计算机上将出现以下屏幕:
命令成功执行后,frame 框架内的文本 - BOTTOM 将打印到控制台中。