获取值

获取用户界面控件内包含的值。

命令可用性: 本地 IBM RPA SaaS 和 IBM RPA

脚本语法

IBM RPA 的专有脚本语言的语法与其他编程语言类似。 该脚本语法在脚本文件中定义命令的语法。 您可以在 IBM RPA Studio的 脚本 方式下使用此语法。

getValue [--forcerefresh(Boolean)] --selector(ControlSelectors) --id(String) --name(String) --innertext(String) --tagname(String) --xpath(String) --classname(String) --elementvalue(String) --controltype(Nullable<ControlTypes>) --index(Numeric) --control(Control) [--usetable(Boolean)] [--searchbycolumn(Boolean)] --searchcolumn(String) --searchvalue(String) --returncolumn(String) --row(Numeric) [--timeout(TimeSpan)] (String)=value (Numeric)=index (StringDictionary<String>)=selectedvalues (StringKeyValuePair<String>)=firstvalue

依赖关系

在使用获取值 (getValue) 命令之前,使用启动并附加窗口启动或附加窗口命令来启动 Windows 作用域。

输入参数

下表显示了此命令中提供的输入参数的列表。 在表中,您可以看到在 IBM RPA Studio的脚本方式及其 Designer 方式等效标签中工作时的参数名称。

设计器方式标签 脚本方式名称 必需的 接受的变量类型 Description
更新屏幕高速缓存 forcerefresh Optional Boolean 启用以读取屏幕来识别新元素和更新屏幕高速缓存。 在运行该命令之前会读取屏幕。

如果屏幕上有任何更改,那么必须启用此参数。
选择器 selector Required ControlSelectors 用于标识用户界面控件的选择器类型。

您可以使用 IBM RPA Studio的记录器来映射控件并获取此参数所需的信息。

请参阅 选择器参数选项
标识 id Required when the Selector parameter is Id, IdAndName Text 控件的唯一标识。

在 SAP GUI 中,使用标识选择器来映射 GridView 控件。 请参阅 映射 GridView 控件 ,以获取有关 GridView 标识选择器工作方式的详细信息。
名称 name Required when the parameter is Name, NameAndValue, IdAndName, TypeAndName Text 控件名称。
文本 innertext Required when the Selector parameter is InnerTextAndTag Text 控件显示的内部文本。
元素类型 tagname Required when the Selector parameter is InnerTextAndTag Text 控件的标记名称。
XPath xpath Required when the Selector parameter is XPath Text 通过控件树到目标控件的路径。
classname Required when the Selector parameter is ClassAndValue, ClassName Text 用于实例化控件的类的名称。
元素值 elementvalue Required when the Selector parameter is ClassAndValue, NameAndValue Text 通过控件存储的值。
类型 controltype Required when the Selector parameter is TypeAndIndex, TypeAndName ControlTypes 控件的类型。

请参阅 controltype 参数选项
索引 index Required when the Selector parameter is TypeAndIndex Number 控件位置。 索引以零开头,它是同等类型中的第一个控件。
控件 control Required when the Selector parameter is Instance Control 控件实例。

通过搜索控件命令来获取 Control 变量类型。
表中的元素 usetable Optional Boolean 启用后,将在表中搜索元素。
按列搜索 searchbycolumn Optional Boolean 启用以在表的特定列中搜索元素。
searchcolumn Required when the Element in Table parameter is True Text 要在其中搜索元素的列名或索引。
searchvalue Required when the Search by Column parameter is True Text 这是用于在表中搜索元素的值。
返回列 returncolumn Required when the Search by Column parameter is True Text 包含控件的列。
row Required when the Search by Column parameter is False Number 用于获取元素的行号。

要关闭此参数,请启用按列搜索参数。
Timeout timeout Optional Time Span, Number, Text 查找控件所需的最长等待时间。 如果为空白,那么缺省超时为 5 秒。

selector 参数选项

下表显示了可用于 selector 输入参数的选项。 该表显示了在脚本方式下工作时的可用选项以及在设计器方式下的等效标签。

设计器方式标签 脚本方式名称 Description
类和值 ClassAndValue 它与控件类名和值匹配。
类名 ClassName 它与用于实例化控件的类名匹配。
标识 Id 它与控件的唯一标识匹配。
标识和名称 IdAndName 它与唯一标识和控件名称匹配。
内部文本和控件类型 InnerTextAndTag 它与控件内部文本及其类型属性匹配。
实例 Instance 它与控件实例匹配。
名称 Name 它与控件名称匹配。
名称和值 NameAndValue 它与控件名称和值匹配。
类型和索引 TypeAndIndex 它与控件类型及其在同等类型控件中的位置索引相匹配。
类型和名称 TypeAndName 它与控件类型和名称匹配。
视觉 Vision 它与标识控件的映射图像匹配。
XPath XPath 它与通过控件树到目标控件的路径匹配。

您可以使用 IBM RPA Studio 的记录器来映射控件和获取以下选择器:

  • 类名
  • 标识
  • 内部文本
  • 链接文本
  • 名称
  • 标记名称
  • XPath

controltype 参数选项

下表显示了可用于 controltype 输入参数的选项。 该表显示了在脚本方式下工作时的可用选项以及在设计器方式下的等效标签。

设计器方式标签 脚本方式名称 Description
按钮 Button 它与应用程序中的“按钮”控件匹配。
复选框 CheckBox 它与应用程序中的“复选框”控件匹配。
子窗口 ChildWindow 它与应用程序中的“子窗口”控件匹配。
组合框 ComboBox 它与应用程序中的“组合框”控件匹配。
常规 Generic 它与应用程序中的“常规”控件匹配。
Image Image 它与应用程序中的“图像”控件匹配。
标签 Label 它与应用程序中的“标签”控件匹配。
列表框 ListBox 它与应用程序中的“列表框”控件匹配。
菜单栏 MenuBar 它与应用程序中的“菜单栏”控件匹配。
菜单项 MenuItem 它与应用程序中的“菜单项”控件匹配。
进度条 ProgressBar 它与应用程序中的“进度条”控件匹配。
单选按钮 RadioButton 它与应用程序中的“单选按钮”控件匹配。
滚动条 ScrollBar 它与应用程序中的“滚动条”控件匹配。
滑块 Slider 它与应用程序中的“滑块”控件匹配。
微调器 Spinner 它与应用程序中的“微调器”控件匹配。
状态栏 StatusBar 它与应用程序中的“状态栏”控件匹配。
选项卡页面 TabPage 它与应用程序中的“选项卡页面”控件匹配。
选项卡面板 TabPanel 它与应用程序中的“选项卡面板”控件匹配。
Table 它与应用程序中的“表”控件匹配。
文本框 TextBox 它与应用程序中的“文本框”控件匹配。
切换按钮 ToggleButton 它与应用程序中的“切换按钮”控件匹配。
树形视图 TreeView 它与应用程序中的“树形视图”控件匹配。
TreeTable TreeTable 它与应用程序中的“树表”控件匹配。
窗口 Window 它与应用程序中的“窗口”控件匹配。

输出参数

设计器方式标签 脚本方式名称 接受的变量类型 Description
value Text 返回 UI 控件中包含的值。
索引 index Number 在 UI 控件中,将所选项的索引作为列表中的项返回。
所选值 selectedvalues String Dictionary<Text> 返回包含在用户界面控件中的值的值键。
第一个所选值 firstvalue String Key Value Pair<Text> 从 UI 控件上获取的值返回第一个值。

示例

以下代码示例演示了如何从记事本应用程序中获取值。 Get Value (getValue) 命令获取名为 "File" 的用户界面控件中包含的值。 在记事本应用程序关闭后,日志消息 (logMessage) 命令会记录获取的值。

defVar --name controlValue --type String
defVar --name notepadWindow --type Window
// Launch the notepad application 
launchWindow --executablepath "notepad.exe" notepadWindow=value
// Gets the value contained in the UI control that has the name "File" in Notepad
getValue --selector "Name" --name File controlValue=value
closeWindow --window ${notepadWindow}
// Logs the value obtained by the control
logMessage --message "Obtained control value: ${controlValue}" --type "Info"