# ocrWaitForTextDisplayed

Wait for a specific text to be displayed on the screen.

## Usage[​](#usage "Direct link to Usage")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

});
```

## Output[​](#output "Direct link to Output")

### Logs[​](#logs "Direct link to Logs")

```
[0-0] 2024-05-26T04:32:52.005Z INFO webdriver: COMMAND ocrWaitForTextDisplayed(<object>)

......................

# ocrWaitForTextDisplayed uses ocrGetElementPositionByText under the hood, that is why you see the command ocrGetElementPositionByText in the logs

[0-0] 2024-05-26T04:32:52.735Z INFO @wdio/ocr-service:ocrGetElementPositionByText: Multiple matches were found based on the word "specFileRetries". The match "specFileRetries" with score "100%" will be used.
```

## Options[​](#options "Direct link to Options")

### `text`[​](#text "Direct link to text")

* Type

  `string`

* Required

  `yes`

The text you want to search for to click on.

#### Example[​](#example "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({ text: "specFileRetries" });
```

### `timeout`[​](#timeout "Direct link to timeout")

* Type

  `number`

* Default

  `18000 (18 seconds)`

* Required

  `no`

Time in milliseconds. Be aware that the OCR process can take some time, so don't set it too low.

#### Example[​](#example-1 "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries"

    timeout: 25000 // wait for 25 seconds

});
```

### `timeoutMsg`[​](#timeoutmsg "Direct link to timeoutmsg")

* Type

  `string`

* Default

  `Could not find the text "{selector}" within the requested time.`

* Required

  `no`

It overrides the default error message.

#### Example[​](#example-2 "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries"

    timeoutMsg: "My new timeout message."

});
```

### `contrast`[​](#contrast "Direct link to contrast")

* Type

  `number`

* Default

  `0.25`

* Required

  `no`

The higher the contrast, the darker the image and vice versa. This can help to find text in an image. It accepts values between `-1` and `1`.

#### Example[​](#example-3 "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    contrast: 0.5,

});
```

### `haystack`[​](#haystack "Direct link to haystack")

* Type

  `number`

* Required

  `WebdriverIO.Element | ChainablePromiseElement | Rectangle`

This is the search area in the screen where the OCR needs to look for text. This can be an element or a rectangle containing `x`, `y`, `width` and `height`

#### Example[​](#example-4 "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    haystack: $("elementSelector"),

});



// OR

await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    haystack: await $("elementSelector"),

});



// OR

await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    haystack: {

        x: 10,

        y: 50,

        width: 300,

        height: 75,

    },

});
```

### `language`[​](#language "Direct link to language")

* Type

  `string`

* Default

  `eng`

* Required

  `No`

The language that Tesseract will recognize. More info can be found [here](https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions) and the supported languages can be found [here](https://github.com/webdriverio/visual-testing/blob/main/packages/ocr-service/src/utils/constants.ts).

#### Example[​](#example-5 "Direct link to Example")

```
import { SUPPORTED_OCR_LANGUAGES } from "@wdio/ocr-service";

await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    // Use Dutch as a language

    language: SUPPORTED_OCR_LANGUAGES.DUTCH,

});
```

### `fuzzyFindOptions`[​](#fuzzyfindoptions "Direct link to fuzzyfindoptions")

You can alter the fuzzy logic to find text with the following options. This might help find a better match

#### `fuzzyFindOptions.distance`[​](#fuzzyfindoptionsdistance "Direct link to fuzzyfindoptionsdistance")

* Type

  `number`

* Default

  `100`

* Required

  `no`

Determines how close the match must be to the fuzzy location (specified by location). An exact letter match which is distance characters away from the fuzzy location would score as a complete mismatch. A distance of 0 requires the match to be at the exact location specified. A distance of 1000 would require a perfect match to be within 800 characters of the location to be found using a threshold of 0.8.

##### Example[​](#example-6 "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    fuzzyFindOptions: {

        distance: 20,

    },

});
```

#### `fuzzyFindOptions.location`[​](#fuzzyfindoptionslocation "Direct link to fuzzyfindoptionslocation")

* Type

  `number`

* Default

  `0`

* Required

  `no`

Determines approximately where in the text is the pattern expected to be found.

##### Example[​](#example-7 "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    fuzzyFindOptions: {

        location: 20,

    },

});
```

#### `fuzzyFindOptions.threshold`[​](#fuzzyfindoptionsthreshold "Direct link to fuzzyfindoptionsthreshold")

* Type

  `number`

* Default

  `0.6`

* Required

  `no`

At what point does the matching algorithm give up. A threshold of 0 requires a perfect match (of both letters and location), a threshold of 1.0 would match anything.

##### Example[​](#example-8 "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    fuzzyFindOptions: {

        threshold: 0.8,

    },

});
```

#### `fuzzyFindOptions.isCaseSensitive`[​](#fuzzyfindoptionsiscasesensitive "Direct link to fuzzyfindoptionsiscasesensitive")

* Type

  `boolean`

* Default

  `false`

* Required

  `no`

Whether the search should be case sensitive.

##### Example[​](#example-9 "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    fuzzyFindOptions: {

        isCaseSensitive: true,

    },

});
```

#### `fuzzyFindOptions.minMatchCharLength`[​](#fuzzyfindoptionsminmatchcharlength "Direct link to fuzzyfindoptionsminmatchcharlength")

* Type

  `number`

* Default

  `2`

* Required

  `no`

Only the matches whose length exceeds this value will be returned. (For instance, if you want to ignore single character matches in the result, set it to 2)

##### Example[​](#example-10 "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    fuzzyFindOptions: {

        minMatchCharLength: 5,

    },

});
```

#### `fuzzyFindOptions.findAllMatches`[​](#fuzzyfindoptionsfindallmatches "Direct link to fuzzyfindoptionsfindallmatches")

* Type

  `number`

* Default

  `false`

* Required

  `no`

When `true`, the matching function will continue to the end of a search pattern even if a perfect match has already been located in the string.

##### Example[​](#example-11 "Direct link to Example")

```
await browser.ocrWaitForTextDisplayed({

    text: "specFileRetries",

    fuzzyFindOptions: {

        findAllMatches: 100,

    },

});
```
