Learning Resources

Regular Expression

Of the three type of patterns, Regular Expressions are the one that are the most useful. Selenium supports the complete set of RegEx patterns that Javascript supports. So now you are not limited by the *,? And [] globbing patterns. To use RegEx patterns you need to prefix each RegEx with either regexp: or regexpi:, the latter being case-insensitive.

For example the following will test if a input field with the id ‘name’ contains the string ‘javascript’, ‘JavaScript’ or ‘Javascript’.

Command Target Value
clickAndWait link=search  
verifyValue id=name regexp:[Jj]ava([Ss]cript)

Below are a few common regular expression patterns:

regexp:(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d
:match a date in ‘mm/dd/yyyy’ format with any of the ‘-’, ‘/’, ‘.’ as separators.

:match a generic email address.

:match a ZIP code (U.S. postal code), allowing both the five-digit and nine-digit (ZIP + 4) formats.

:match U.S Social Security numbers in the in the AAA-GG-SSSS format.

:match almost any url.