等待窗口出现

等待打开的窗口,并将其存储在 "窗口" 类型变量中。

描述

等待与指定选择器相对应的打开窗口出现,将该窗口存储在 "窗口" 类型变量中。 存储的窗口将自动附加到驱动程序的活动窗口上下文。 您可以使用它来验证窗口是否处于打开状态,或者在多个窗口之间更改焦点时是否处于打开状态。

要从窗口获取选择器,请参阅 控件和选择器概述 以获取详细说明。

脚本语法

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

waitWindow [--useregex(Boolean)] [--title(String)] --regexPattern(String) [--regexOptions(DisplayableRegexOptions)] [--id(String)] [--classname(String)] [--processid(Numeric)] [--processname(String)] [--byparent(Boolean)] [--window(Window)] [--recursive(Boolean)] [--safesearch(Boolean)] [--styles(Nullable<AutomationWindowStyles>)] [--minimumheight(Numeric)] [--minimumwidth(Numeric)] [--timeout(TimeSpan)] (Window)=value (Numeric)=processId (Boolean)=success

输入参数

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

设计器方式标签 脚本方式名称 必需的 接受的变量类型 描述
使用正则表达式 useregex Optional Boolean 启用以使用正则表达式来标识应该等待的窗口。
标题 title Optional Text 应等待的窗口的标题。
正则表达式 regexPattern Required only when Use Regular Expression is True Text 用于识别应等待的窗口的正则表达式。
选项 regexOptions Optional DisplayableRegexOptions 正则表达式匹配的选项。

请参阅 regexoptions 参数选项
标识 id Optional Text 应等待的窗口的标识。
类名 classname Optional Text 应等待的窗口的类名。
进程标识 processid Optional Number 窗口所属进程的标识。
进程名称 processname Optional Text 此窗口所属的进程的名称。
等待子窗口 byparent Optional Boolean 启用以允许等待父窗口的子窗口。
窗口 window Optional Window 要等待的子窗口的父代。
递归 recursive Optional Boolean 启用以允许在窗口中等待窗口。
安全搜索 safesearch Optional Boolean 启用以运行更高性能的窗口搜索算法。
样式 styles Optional AutomationWindowStyles 等待的窗口样式: "子代" , "对话"。
最小高度 minimumheight Optional Number 等待的窗口的最小高度。
最小宽度 minimumwidth Optional Number 等待的窗口的最小宽度。
Timeout timeout Optional Time Span, Number, Text 命令执行超时。 如果在 timeout 参数中未定义任何值,那么执行将使用 设置超时 (setTimeout) 命令定义的上下文时间。 如果脚本未使用此命令,那么缺省时间为 5 秒。

regexOptions 参数选项

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

设计器方式标签 脚本方式名称 描述
已编译 Compiled 编译正则表达式而不是解释。
区域固定格式 CultureInvariant 忽视语言上的文化差异。
ECMA 脚本 ECMAScript 解释 ECMA 脚本表达式。
忽略大小写 IgnoreCase 不区分大小写的搜索。
显式捕获 ExplicitCapture 唯一有效的捕获是格式为?<name> subexpression的显式命名或编号的组。
忽略模式空格 IgnorePatternWhitespace 忽略空格字符,并在数字符号 (#) 后启用注释。
从右到左 RightToLeft 从右到左或从最后到第一个读取正则表达式。
单行 Singleline 更改点 (.) 的含义,它与除
以外的每个字符匹配。
多行 Multiline 允许插入标记 (^) 和美元符号 ($) 符号与换行符匹配。

输出参数

设计器方式标签 脚本方式名称 接受的变量类型 描述
窗口 value Window 返回等待的窗口。
进程标识 processId Number 返回进程标识。
成功 success Boolean 如果找到窗口,那么返回 True ,否则返回 False

示例

在此特定示例中,命令将验证 Outlook 应用程序是否已打开。 如果不是,那么它将运行子例程以启动 Outlook 应用程序。 在启动应用程序并将其自动附加到驱动程序的活动窗口上下文之后,将根据排除的词的列表来应用搜索过滤器。 然后,它将返回具有列表中任何词的电子邮件数量。

defVar --name windowStatus --type Boolean
defVar --name outlookConnection --type EmailConnection
defVar --name countMessages --type Numeric
defVar --name listExcludeWords --type List --innertype String --value "[word1,word2,word3]"
// Verifies if the Outlook application is opened.
waitWindow --title "Inbox <-user@ibm.com|-user@ibm.com> - Outlook" --classname rctrl_renwnd32 --processname outlook windowStatus=success
// Runs a subroutine to start the Outlook application in case it is not open.
gosubIf --label openOutlook --left "${windowStatus}" --operator "Is_True" --negate
// Connects to the Outlook application.
outlookConnect --mailusername "useremail@email.com" outlookConnection=value
// Applies search filters, in this case, based on a list of excluded words.
emailApplySearchFilters --folderpath Inbox --subjectdirective "All" --exclusivesubject ${listExcludeWords} --wordsdirective "All" --connection ${outlookConnection}
// Counts the amount of emails returned based on the filter.
emailCount --connection ${outlookConnection} countMessages=value
// Prints the amount of emails that have any word from the excluded words list.
logMessage --message "Quantity of emails that have words from the list of excluded words: ${countMessages}" --type "Info"
beginSub --name openOutlook
// The subroutine to start the Outlook application.
	launchWindow --executablepath "C:\\Program Files\\Microsoft Office\\root\\Office16\\outlook.exe"
endSub