Selenium Testing | Using Exact

Using Exact

Selenium Testing | Using Exact

Selenium Testing – Using Exact

Patterns with the prefix ‘exact:’ will match the given text as it is. For example, if you give the search pattern as below, then it will match a glob pattern ‘*’ or ‘*.java’.

Command Target Value
clickAndWait link=search  
verifyValue glob: *.java  

But if you want an exact match with the value string, i.e without the glob operator doing its work, you use the ‘exact’ pattern as below. In this example, the ‘*’ (asterisk) will work as a normal character rather than a pattern-matching wildcard character.

Command Target Value
clickAndWait link=search  
verifyValue exact: *.java  

In conclusion, the glob: and the exact: pattern are the subsets of the Regular Expression pattern matcher. Everything you can do with glob: or exact: you can accomplish with RegExp.

Like locators, patterns are a type of parameter frequently required by Selenese commands. Examples of commands which require patterns are verifyTextPresent, verifyTitle, verifyAlert, assertConfirmation, verifyText, and verifyPrompt. And as has been mentioned above, link locators can utilize a pattern. Patterns allow you to describe, via the use of special characters, what text is expected rather than having to specify that text exactly.

There are three types of patterns: globbing, regular expressions, and exact.

Exact Patterns

The exact type of Selenium pattern is of marginal usefulness. It uses no special characters at all. So, if you needed to look for an actual asterisk character (which is special for both globbing and regular expression patterns), the pattern would be one way to do that. For example, if you wanted to select an item labeled “Real *” from a dropdown, the following code might work or it might not. The asterisk in the glob:Real * pattern will match anything or nothing. So, if there was an earlier select option labeled “Real Numbers,” it would be the option selected rather than the “Real *” option.

select //select glob:Real *

In order to ensure that the “Real *” item would be selected, the exact: prefix could be used to create a pattern as shown below:

select //select exact:Real *

But the same effect could be achieved via escaping the asterisk in a regular expression pattern:

select //select regexp:Real \*

It’s rather unlikely that most testers will ever need to look for an asterisk or a set of square brackets with characters inside them (the character class for globbing patterns). Thus, globbing patterns and regular expression patterns are sufficient for the vast majority of us.

 

Selenium professional free practice test

Go back to Tutorial                                                                                Go to Home Page

Selenium testing | Matching Text Patterns
Vskills Certified Selenium Professional Tutorial | Globs

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?