等待元素出现在 Web 页面中
等待某个元素出现在 Web 页面上。
命令可用性: 本地 IBM RPA SaaS 和 IBM RPA
Description
等待某个元素出现在 Web 页面上。 使用选择器类型来识别元素,并验证该元素是否存在于 Web 页面上。
脚本语法
IBM RPA 的专有脚本语言具有类似于其他编程语言的语法。 该脚本语法在脚本文件中定义命令的语法。 您可以在 IBM RPA Studio的 脚本 方式下使用此语法。
webWaitElement --selector(WebElementSelectors) --id(String) --name(String) --css(String) --linktext(String) --innertext(String) --tagname(String) --xpath(String) --class(String) --elementvalue(String) [--simulatehuman(Boolean)] [--timeout(TimeSpan)] (Boolean)=value
依赖关系
在使用等待元素出现在 Web 页面中 (webWaitElement) 命令之前,请使用启动浏览器 (webStart) 命令来启动浏览器或使用查找 Internet Explorer 浏览器 (findBrowser) 命令来连接 Microsoft Internet Explorer。
输入参数
下表显示了此命令中提供的输入参数的列表。 在表中,您可以看到在 IBM RPA Studio的脚本方式及其 Designer 方式等效标签中工作时的参数名称。
| 设计器方式标签 | 脚本方式名称 | 必需的 | 接受的变量类型 | Description |
|---|---|---|---|---|
| 选择器 | selector |
Required |
WebElementSelectors |
用于标识 Web 页面中的 Web 元素的选择器类型。 请参阅 selector 参数选项。 |
| 标识 | id |
Required when the Selector parameter is Id, IdAndName |
Text |
包含标识属性值的文本,以与要显示的元素匹配。 |
| 元素名称 | name |
Required when the Selector parameter is Name, NameAndValue, IdAndName |
Text |
包含名称属性值的文本,以与要显示的元素匹配。 |
| CSS | css |
Required when the Selector parameter is CssSelector |
Text |
包含 CSS 选择器的文本,以与要显示的元素匹配。 |
| 链接文本 | linktext |
Required when the Selector parameter is LinkText |
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 |
包含 XML 路径值的文本,以与要显示的元素匹配。 |
| 类名 | class |
Required when the Selector parameter is ClassAndValue |
Text |
包含类属性值的文本,以与要显示的元素匹配。 |
| 元素值 | elementvalue |
Required when the Selector parameter is ClassAndValue, NameAndValue |
Text |
包含“值”属性值的文本,以与要显示的元素匹配。 |
| 模拟人类 | simulatehuman |
Optional |
Boolean |
此参数不会更改命令的行为。 |
| Timeout | timeout |
Optional |
Time Span, Number, Text |
运行命令时的最长等待时间。 如果为空白,那么缺省超时为 5 秒。 |
selector 参数选项
下表显示了可用于 selector 输入参数的选项。 该表显示了在脚本方式下工作时的可用选项以及在设计器方式下的等效标签。
| 设计器方式标签 | 脚本方式名称 | Description |
|---|---|---|
| 标识 | Id |
根据标识属性值匹配 Web 元素。 |
| 名称 | Name |
根据“名称”属性值匹配 Web 元素。 |
| Css | CssSelector |
根据 CSS 选择器值匹配 Web 元素。 |
| 链接文本 | LinkText |
根据链接文本属性值与 Web 元素相匹配。 |
| 内部文本和控件类型 | InnerTextAndTag |
根据元素文本内容和标记名称属性值与 Web 元素相匹配。 |
| XPath | XPath |
根据 HTML 根中的 XML 路径匹配 Web 元素。 |
| 类和值 | ClassAndValue |
根据类名和值属性与 Web 元素相匹配。 |
| 名称和值 | NameAndValue |
基于名称和值属性与 Web 元素匹配。 |
| 标识和名称 | IdAndName |
根据标识和名称属性值匹配 Web 元素。 |
输出参数
| 设计器方式标签 | 脚本方式名称 | 接受的变量类型 | Description |
|---|---|---|---|
| 成功 | value |
Boolean |
如果元素出现,那么返回 true,否则返回 false。 |
示例
等待 Web 页面中的元素 (webWaitElement) 检查搜索字段是否可用于输入值 "IBM"。 在此情况下,浏览器保持打开状态,但如果元素未出现,那么浏览器将关闭。
defVar --name elementAppears --type Boolean
webStart --name browser --type "Chrome"
webNavigate --url "https://google.com"
// The command checks if the search field is on the web page, the "IBM" value will only be entered if the search field is displayed within 10 seconds.
webWaitElement --selector "Name" --name q --timeout "00:00:10" elementAppears=value
if --left "${elementAppears}" --operator "Is_True"
webSet --value "IBM" --selector "Name" --name q
webClose --name browser --leavebrowseropen
// Keep the browser open.
else
webClose --name browser
logMessage --message "----------\r\nCommand result: ${elementAppears}\r\nThe element isn\'t available.\r\n-----------" --type "Info"
endIf
限制
- 当使用 XPath 或 CSS 选择器与不唯一的 Web 元素进行交互时,即在 IFrame 内,需要指定命令将与 IFrame 内的哪个元素进行交互。 否则,将仅查找第一个元素。