搜索控件
动词:searchControl
根据定义的参数查找控件的实例。
语法
searchControl [--window(String)] [--indexedpath(String)] [--id(String)] [--name(String)] [--innertext(String)] [--elementvalue(String)] [--classname(String)] [--controltype(String)] [--index(Numeric)] [--width(Numeric)] [--height(Numeric)] [--timeout(TimeSpan)] (Boolean)=success (Control)=value
输入
| 脚本 | 设计器 | 必需的 | AcceptedTypes | Description |
|---|---|---|---|---|
| --window | 窗口 | 可选 | 文本、窗口 | 控件窗口的标题或变量。 |
| --indexedpath | 索引路径 | 可选 | 文本 | 控件索引路径。“索引路径”基于 Microsoft Active Accessibility (MSAA) 技术。 树节点的路径用逗号分隔,并且每个索引对应一个元素。 仅当设置了 indexedpath 时,搜索控件命令才会应用 MSAA 索引路径搜索,否则,将使用 UIAutomation API 搜索。 对所有选择器求值时,会将 AND 逻辑连接用于始终要第一个求值的 MSAA 索引路径。 最终,即使设置了 indexedpath,对象也会转换为 UIAutomation 句柄。 |
| -- 标识 | 标识 | 可选 | 文本 | 应查找的控件的标识。 |
| -- 名称 | 名称 | 可选 | 文本 | 应查找的控件的名称。 |
| --innertext | 文本 | 可选 | 文本 | 应查找的控件的内部文本。 |
| --elementvalue | 元素值 | 可选 | 文本 | 应查找的控件的元素值。 |
| --classname | 类 | 可选 | 文本 | 应查找的控件的类。 |
| --controltype | 类型 | 可选 | 文本 | 应查找的控件的类型。 |
| -- 索引 | 索引 | 可选 | 成员 | 应查找的控件的索引。 |
| --width | 控件宽度 | 可选 | 成员 | 应查找的控件的准确宽度。 |
| --height | 控件高度 | 可选 | 成员 | 应查找的控件的高度。 |
| --timeout | 超时 | 可选 | 时间范围、数字、文本 | 执行命令的最长时间限制。 如果没有为超时参数定义值,那么将使用设置超时命令定义的上下文超时来执行脚本。 如果脚本中未使用该命令,那么缺省超时为 5 秒。 |
输出
| 脚本 | 设计器 | AcceptedTypes | Description |
|---|---|---|---|
| 成功 | 成功 | BOOLEAN | 如果找到控件,那么返回“True”;否则,返回“False”。 |
| 值 | 控件 | 控件 | 返回控件的实例。 |
示例
“Notepad”的实例已在未附加到上下文的情况下启动,因此使用搜索控件命令找到该实例并将其附加到当前上下文,然后将文本文件保存在用户的桌面上。
defVar --name controlInstance --type Control
defVar --name successSearch --type Boolean
defVar --name desktopPath --type String
defVar --name successSave --type Boolean
getSpecialFolder --folder "Desktop" desktopPath=value
openFile --file "notepad.exe"
searchControl --window "Untitled - Notepad" --indexedpath "3,1,1,4" --timeout 01:01:00 --comment "File -> Save as" successSearch=success controlInstance=value
logMessage --message "\r\n${successSearch}" --type "Info"
if --left "${successSearch}" --operator "Is_True"
click --selector "Instance" --control ${controlInstance}
endIf
handleSaveFileDialog --filepath "${desktopPath}\\Example.txt" successSave=success
logMessage --message "\r\n${controlInstance.Window.Title}\r\n${successSave}" --type "Info"