web » select(locator,text)
This command automates the selection of OPTION
element(s) from a SELECT
element identified via locator
. The
target OPTION
element is identified via text
, which could be plain text for single element identification (i.e.
exact match) or regex-based element identification (i.e. multi-match). For example, suppose the following SELECT
element:
To select “American flamingo”, one would specify text
as American flamingo
. However, one can also specify text
as
REGEX:American.+
(reads: starts with “American”). Similarly, to select “Lesser flamingo”, one can specify text
as REGEX:Lesser.+
.
Now suppose we have a SELECT
element that suppose multi-select:
To select both “Andean flamingo” and “Chilean flamingo”, one would specify text
as REGEX:.+ean .+
(reads: contains “ean “).
PolyMatcher - a flexible way to perform text matching
In addition to extract text matching (or string matching), this command/expression also supports "polymatcher" (as of v3.6). With polymatcher, one can instruct Nexial to match the intended text in a less exact (but more expressiveness) way. Here are the supported matching strategies:
-
CONTAIN:
: Use this technique to perform partial text matches. For example: useCONTAIN:completed
as intent for "matching text that contains the text ‘completed’". -
CONTAIN_ANY_CASE:
: Use this technique to perform partial text matches (same asCONTAIN:
), except without considering the uppercase/lowercase variants. For example,CONTAIN_ANY_CASE:Successfully
would match "Completed successfully", "Completed Successfully", and "COMPLETED SUCCESSFULLY". -
START:
: Use this technique to perform "starts with" text matches. For example,START:Greetings
matches any text starting with the text "Greetings". -
START_ANY_CASE:
: Use this technique to perform "starts with" text matches without considering letter casing. For example,START_ANY_CASE:Greetings
matches any text starting with the text "Greetings", "GREETINGS", "greetings", "greeTINGs", etc. -
END:
: Use this technique to perform "ends with" text matches. For example,END:Please try again.
matches any text that ends with the text "Please try again.". -
END_ANY_CASE:
: Use this technique to perform "ends with" text matches without considering letter casing. For example,END_ANY_CASE:Please try again.
matches any text that ends with the text "Please try again." in any combination of upper or lower case. -
REGEX:
: Use this technique to perform text matching via regular expression. For example: useREGEX:.+[S|s]uccessfully.*
as intent for "matching text that contains 1 or more character, then either ‘Successfully’ or ‘successfully’, follow by zero or more characters.". -
EMPTY:[true|false]
: Use this technique to perform "is empty?" check.EMPTY:true
means that the target value is expected to be empty (no content or length).EMPTY:false
means the target value is expected NOT to be empty (with content). -
BLANK:[true|false]
: Use this technique to perform "is blank?" check.BLANK:true
means that the target value is expected to contain blank(s) or whitespace (space, tab, newline, line feed, etc.) characters or empty (no content or length).BLANK:false
means the target value is expected to contain at least 1 non-whitespace character. Note that this matcher includes teEMPTY:
check as well. -
LENGTH:
: Use this technique to perform text length validation against target value. One may use a numeric comparator for added flexibility/expressiveness. For example:LENGTH:5
means to match the target value to a length of 5.LENGTH: > 5
means to match the target value to a length greater than 5. The available comparators are:>
,>=
,<
,<=
,=
,!=
. -
NUMERIC:
: Use this technique to perform numeric comparison/matching against target value. With this technique,100
considered the same as100.00
since both value has the same numerical value. One may use a numeric comparator for added flexibility/expressiveness. For example:NUMERIC:5
means to match the target value to the number5
.NUMERIC: <= -15.02
means to match the target value as a number that is less or equal to-15.02
. The available comparators are:>
,>=
,<
,<=
,=
,!=
. -
EXACT:
: Use this to perform exact text matching, i.e. equality matching. In most cases, this is not required as the absence of any special keyword almost always means the "is this the same as that?" test. However in some special cases such as base »assertMatch(text,regex)
, one may use thisEXACT:
syntax to indicate match by equality instead of regular expression. - And, of course, one can still use the exact matching strategy by specifying the exact text to match.
We will be adding new strategy to polymatcher – Please feel free to request for new ones!
Supporting index-based selection
As of v4.4, Nexial supports the selection of a OPTION
element using its
index. To do so, specify the text
parameter in the form of INDEX:[number]
. Note that the specified index is assumed
to be 0-based. A special case of INDEX:last
is also supported to select the last OPTION
element. For example,
INDEX:1
would select the second OPTION
element belonging to the target SELECT
element, while INDEX:last
would
select the last OPTION
element instead.
Note
- If multiple matches are found through regex-based identification but the target
SELECT
element only support single selection, then only the first one will be selected. - If the regex-based identification yielded no matches, then
text
will be retried as exact match. This means Nexial will look for aOPTION
element under the targetSELECT
element that contains the textREGEX:...
. - The
REGEX:
capability works for bothselect(locator,text)
anddeselect(locator,text)
command. - If
text
is{ALL}
and the targetSELECT
element supports multi-select, then ALL itsOPTION
elements will be selected.
Parameters
- locator - the locator of the
SELECT
element. - text - the text to be selected on the
SELECT
element. As said earlier, it supportsRegex:
capability as well as{ALL}
to select all options.
Example
Script:
Output:
Select all the option(multi-select):
Script:
After selection: