- 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 - 链接文本定位器
- WebdriverIO - ID 定位器
- WebdriverIO - 标签名定位器
- WebdriverIO - 类名定位器
- WebdriverIO - 名称定位器
- 断言的 Expect 语句
- WebdriverIO - 成功路径流程
- WebdriverIO - 通用浏览器命令
- WebdriverIO - 处理浏览器大小
- WebdriverIO - 浏览器导航命令
- 处理复选框和下拉菜单
- WebdriverIO - 鼠标操作
- 处理子窗口/弹出窗口
- WebdriverIO - 隐藏元素
- WebdriverIO - 框架
- WebdriverIO - 拖放
- WebdriverIO - 双击
- WebdriverIO - Cookie
- WebdriverIO - 处理单选按钮
- Web元素上的 Chai 断言
- WebdriverIO - 多个窗口/标签页
- WebdriverIO - 滚动操作
- WebdriverIO - 警报
- WebdriverIO - 调试代码
- WebdriverIO - 捕获屏幕截图
- WebdriverIO - JavaScript 执行器
- WebdriverIO - 等待
- WebdriverIO - 并行运行测试
- WebdriverIO - 数据驱动测试
- 从命令行参数运行测试
- 使用 Mocha 选项执行测试
- 从 Allure 生成 HTML 报告
- WebdriverIO 有用资源
- WebdriverIO - 快速指南
- WebdriverIO - 有用资源
- WebdriverIO - 讨论
WebdriverIO - JavaScript 执行器
在 WebdriverIO 内部,JavaScript 执行器被捆绑并称为 executeScript。当正常的 WebdriverIO 方法无法按预期工作时,JavaScript 执行器能够在页面上执行所有任务。
语法
JavaScript 执行器的语法如下:
browser.executeScript("JavaScript command")
使用 JavaScript 执行器执行的操作
使用 JavaScript 执行器执行的一些操作如下:
要将文本 - AB 输入到 id 为 txt 的编辑框中,请使用以下命令:
browser.executeScript("document.getElementById('txt').value='AB'")
要点击链接,请使用以下命令:
browser.executeScript("document.querySelector('.lnk').click()")
以下命令用于刷新窗口:
browser.executeScript("history.go(0)")
var t = js.executeScript("return document.getElementById('bln').innerHTML").toString()
向下滚动页面 350 像素的命令如下:
browser.executeScript("window.scrollBy(0,350)")
browser.executeScript("window.scrollTo(0, document.body.scrollHeight)")
以下命令用于向下滚动到类为 tcl 的元素。
browser.executeScript("document.querySelector('.tcl').scrollIntoView()")
browser.executeScript("window.history.back()")
以下命令用于在浏览器历史记录中前进:
browser.executeScript("window.history.forward()")
browser.executeScript("return document.title")
广告