
- Selenium 教程
- Selenium - 首页
- Selenium - 概述
- Selenium - 组件
- Selenium - 自动化测试
- Selenium - 环境设置
- Selenium - 远程控制
- Selenium IDE 教程
- Selenium - IDE 简介
- Selenium - 功能
- Selenium - 限制
- Selenium - 安装
- Selenium - 创建测试
- Selenium - 创建脚本
- Selenium - 控制流
- Selenium - 存储变量
- Selenium - 警报和弹出窗口
- Selenium - Selenese 命令
- Selenium - 操作命令
- Selenium - 获取器命令
- Selenium - 断言命令
- Selenium - Assert/Verify 方法
- Selenium - 定位策略
- Selenium - 脚本调试
- Selenium - 验证点
- Selenium - 模式匹配
- Selenium - JSON 数据文件
- Selenium - 浏览器执行
- Selenium - 用户扩展
- Selenium - 代码导出
- Selenium - 代码输出
- Selenium - JavaScript 函数
- Selenium - 插件
- Selenium WebDriver 教程
- Selenium - 简介
- Selenium WebDriver vs RC
- Selenium - 安装
- Selenium - 第一个测试脚本
- Selenium - 驱动程序会话
- Selenium - 浏览器选项
- Selenium - Chrome 选项
- Selenium - Edge 选项
- Selenium - Firefox 选项
- Selenium - Safari 选项
- Selenium - 双击
- Selenium - 右键单击
- Python 中的 HTML 报告
- 处理编辑框
- Selenium - 单个元素
- Selenium - 多个元素
- Selenium Web 元素
- Selenium - 文件上传
- Selenium - 定位器策略
- Selenium - 相对定位器
- Selenium - 查找器
- Selenium - 查找所有链接
- Selenium - 用户交互
- Selenium - WebElement 命令
- Selenium - 浏览器交互
- Selenium - 浏览器命令
- Selenium - 浏览器导航
- Selenium - 警报和弹出窗口
- Selenium - 处理表单
- Selenium - 窗口和标签页
- Selenium - 处理链接
- Selenium - 输入框
- Selenium - 单选按钮
- Selenium - 复选框
- Selenium - 下拉框
- Selenium - 处理 IFrame
- Selenium - 处理 Cookie
- Selenium - 日期时间选择器
- Selenium - 动态 Web 表格
- Selenium - Actions 类
- Selenium - Action 类
- Selenium - 键盘事件
- Selenium - 键上/下
- Selenium - 复制和粘贴
- Selenium - 处理特殊键
- Selenium - 鼠标事件
- Selenium - 拖放
- Selenium - 笔事件
- Selenium - 滚动操作
- Selenium - 等待策略
- Selenium - 显式/隐式等待
- Selenium - 支持功能
- Selenium - 多选
- Selenium - 等待支持
- Selenium - 选择支持
- Selenium - 颜色支持
- Selenium - ThreadGuard
- Selenium - 错误和日志记录
- Selenium - 异常处理
- Selenium - 其他
- Selenium - 处理 Ajax 调用
- Selenium - JSON 数据文件
- Selenium - CSV 数据文件
- Selenium - Excel 数据文件
- Selenium - 跨浏览器测试
- Selenium - 多浏览器测试
- Selenium - 多窗口测试
- Selenium - JavaScript 执行器
- Selenium - 无头执行
- Selenium - 捕获屏幕截图
- Selenium - 捕获视频
- Selenium - 页面对象模型
- Selenium - 页面工厂
- Selenium - 记录和回放
- Selenium - 框架
- Selenium - 浏览上下文
- Selenium - DevTools
- Selenium Grid 教程
- Selenium - 概述
- Selenium - 架构
- Selenium - 组件
- Selenium - 配置
- Selenium - 创建测试脚本
- Selenium - 测试执行
- Selenium - 端点
- Selenium - 自定义节点
- Selenium 报告工具
- Selenium - 报告工具
- Selenium - TestNG
- Selenium - JUnit
- Selenium - Allure
- Selenium 和其他技术
- Selenium - Java 教程
- Selenium - Python 教程
- Selenium - C# 教程
- Selenium - Javascript 教程
- Selenium - Kotlin 教程
- Selenium - Ruby 教程
- Selenium - Maven 和 Jenkins
- Selenium - 数据库测试
- Selenium - LogExpert 日志记录
- Selenium - Log4j 日志记录
- Selenium - Robot Framework
- Selenium - AutoIT
- Selenium - Flash 测试
- Selenium - Apache Ant
- Selenium - Github 教程
- Selenium - SoapUI
- Selenium - Cucumber
- Selenium - IntelliJ
- Selenium - XPath
- Selenium 其他概念
- Selenium - IE 驱动程序
- Selenium - 自动化框架
- Selenium - 基于关键字的框架
- Selenium - 数据驱动框架
- Selenium - 混合驱动框架
- Selenium - SSL 证书错误
- Selenium - 替代方案
- Selenium 有用资源
- Selenium - 问答
- Selenium - 快速指南
- Selenium - 有用资源
- Selenium - 自动化实践
- Selenium - 讨论
Selenium IDE - 获取器命令
Selenium IDE 包含三种命令,称为操作、获取器和断言。获取器命令用于检查应用程序状态,然后将结果存储在变量中。
如何获取获取器命令?
我们可以在 Selenium IDE 中通过在命令字段中输入 store 来获取获取器命令。输入后,所有与 store 相关的命令都可供选择。

示例 1
让我们以以下页面为例,我们将在名字:标签旁边输入文本Selenium,在姓氏:标签旁边输入Tutorialspoint。此外,我们将使用 Selenium IDE 和获取器命令获取文本Selenium - Automation Practice Form。

以下是需要遵循的步骤:
步骤 1 - 重复链接Selenium IDE 存储变量中描述的步骤 1 到 4。
步骤 2 - Selenium IDE 中的工作区现已准备就绪。
步骤 3 - 在命令字段中输入 open,在目标字段中输入Selenium 自动化实践表单,以启动应用程序。

步骤 4 - 在命令字段中输入 store,在目标字段中输入 Selenium,在值字段中输入 i。请注意,Selenium 是我们想使用变量 i 输入的值。

步骤 5 - 在命令字段中输入 type,在目标字段中输入 id=firstname,在值字段中输入 ${i}。请注意,id=firstname 是输入框的定位器值,${i} 用于引用我们想使用变量 i 输入的变量值。
步骤 6 - 在命令字段中输入 store,在目标字段中输入 Tutorialspoint,在值字段中输入 j。请注意,Tutorialspoint 是我们想使用变量 j 输入的值。
步骤 7 - 在命令字段中输入 type,在目标字段中输入 id=lastname,在值字段中输入 ${j}。请注意,id=lastname 是输入框的定位器值,${j} 用于引用我们想使用变量 j 输入的变量值。

步骤 8 - 在命令字段中输入 storeText,在目标字段中输入 css=div > h1,在值字段中输入 k。请注意,css=div > h1 是我们要获取的文本的定位器值,k 用于引用我们将存储获取到的文本的变量值。
步骤 9 - 在命令字段中输入 echo,在目标字段中输入 ${k}。请注意,这将在 Selenium IDE 的日志中打印我们在步骤 10 中访问的网页上的文本。

步骤 10 - 在命令字段中输入 storeValue,在目标字段中输入 id=firstname,在值字段中输入 l。请注意,id=firstname 是输入框的定位器值,l 用于引用我们将用来获取输入框中输入值的变量。
步骤 11 - 在命令字段中输入 echo,在目标字段中输入 ${l}。请注意,这将在 Selenium IDE 的日志中打印我们在步骤 7 中输入的值。

步骤 12 - 在命令字段中输入 close 以关闭浏览器窗口。

步骤 13 - 点击左侧面板中出现的三个点,然后选择“重命名”选项。

步骤 14 - 在“重命名测试用例”字段下输入名称,例如 TestCase2,然后点击“重命名”。输入的名称将出现在 Selenium IDE 的左侧。

步骤 15 - 点击顶部的“运行所有测试”,然后等待测试执行完成。在我们的示例中,我们将看到运行:1,失败:0,以及一个绿色条表示测试成功运行且没有任何失败。此外,“TestCase2 成功完成”消息也会出现在日志中。

在上面的示例中,我们获得了出现在网页上的文本Selenium - Automation Practice Form,还在日志中检索了在名字:标签旁边的输入框中输入的值 - Selenium。此外,我们在测试用例名称 - TestCase2 的旁边得到了一个绿色勾号,表示测试通过。
因此,在 Selenium IDE 中,我们将获得测试结果的测试步骤级别信息,并且只有在所有步骤都成功执行后,我们才能在测试用例级别获得 PASS。
此外,我们可以推断出在一个步骤中使用的变量可以使用语法:${<变量名>} 在其他步骤中访问。在步骤 6、7、8、9、10、11、12 和 13 中,我们在测试中采用了这种方法。此外,我们使用了 store 和 store 相关的命令,如 storeText、storeValue 等来存储变量。echo 命令用于在“日志”选项卡下打印这些值。

示例 2
让我们再以以下页面为例,我们将使用获取器命令捕获页面标题 Selenium Practice - Radio Button。

捕获浏览器标题的步骤如下所示:
步骤 1 - 按照前一个示例中的步骤 1 到 4 操作。
步骤 2 - 在命令字段中输入 open,在目标字段中输入Selenium 自动化实践表单,以启动应用程序。
步骤 3 - 在命令字段中输入 storeTitle,在值字段中输入 pageTitle。请注意,pageTitle 是捕获已启动页面的标题的变量。
步骤 4 - 在命令字段中输入 echo,在目标字段中输入 ${pageTitle}。请注意,这将在 Selenium IDE 的日志中打印我们在步骤 3 中获得的文本。

步骤 5 - 按照前一个示例中的步骤 14 到 17 操作。

在上例中,我们在日志中获得了页面标题Selenium 实践 - 单选按钮。此外,我们在测试用例名称 - Test6 旁边看到一个绿色勾号,表示测试通过。
此外,我们可以推断出,在一个步骤中使用的变量可以使用语法:${<变量名>} 在后续步骤中访问。在步骤 2 和 3 中,我们在测试中使用了这种方法以及 store title 命令来获取页面。echo 命令用于在“日志”选项卡下打印该值。
结论
本教程总结了关于 Selenium IDE 访问器命令的全面内容。我们首先介绍了如何在 Selenium IDE 中访问访问器命令,并逐步讲解了不同的访问器命令,例如 store、store text、store title 等,并说明了如何将它们与 Selenium 一起使用。这使您深入了解 Selenium IDE 中的访问器命令。建议您继续练习所学内容,并探索与 Selenium 相关的其他内容,以加深理解并拓宽视野。