hint method

Class: OcrRegionPlatform: Selenium 3Language: Java SDK:

Use this optional method to define the expected text as literal text or as a pattern.

The hint helps overcome ambiguities that arise when using OCR. It can be used, for example, to disinguish between the numeric '0' (zero) character and the alphabetic 'O' character.

For more information see Eyes OCR support .

This feature is experimental. Please note that the functionality and/or API may change.


BaseOcrRegion value = obj.hint(hint);


Literal text or a regular expression like pattern that defines what text is expected. See the remarks section for details of how to define patterns.

Return value

Type: BaseOcrRegion
This method returns the object that called it so that it can be used to call other methods supportd by this class in a fluent API style.


Defining Patterns and Hints

An OCR pattern/hint may be composed of any of the following characters:

. Matches any character.
\d Matches any digit 0-9.
\l (Lowercase L) Matches any letter a-z or A-Z.
\w Matches any word character a-z, A-Z, or _.
\S Matches any non-space character.
+ Repeats the previous literal character or character class one or more times, for example, "\d+" is any multi-numeral digit and "\w+" is any word that contains only letters or an underscore. This pattern cannot cross a line break.
\ Escapes a character that has a special meaning – specifically use this to specify the literals "\", ".", and "+" by using " \\", "\", and "\+".
space The OCR is tolerant of spaces between characters, so you don’t have to add them to the pattern. Where a space is detected in the image, it is translated into a single space. If you add an explicit space in the pattern, then it matches any number of spaces.
Any other character represents itself.

Depending on the programming language you use, the back-slashed character classes may need to be specially encoded in the string, for example, by using a double back-slash such as "\\w".

Example patterns

  • "\w+": Match a word

  • "\d+": Match a number

  • "\S+" : Match mixed alphabetic and digital data

  • "\d+/\d+/\d+": Match a date, such as 01/04/1972

  • "$\d+.\d+": Match an amount of money, such as $150.00


WebElement logoElement2 = driver.findElement(new By.ByCssSelector("#btn_logo_png"));
List<String> textsFound = eyes.extractText(
        (OcrRegion) new OcrRegion(logoElement2),
        (OcrRegion) new OcrRegion(new Region(60, 50, 200, 80)).hint("applitools"),
        (OcrRegion) new OcrRegion(new By.ByCssSelector("#btn_click_txt")).hint("Click here"),
        (OcrRegion) new OcrRegion(new By.ByTagName("body"))
for (int i = 0; i < textsFound.size(); i++) {
    System.out.printf("%d) found '%s'\n", i, textsFound.get(i));