# ocrGetText

Get the text on an image.

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

```
const result = await browser.ocrGetText();



console.log("result = ", JSON.stringify(result, null, 2));
```

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

### Result[​](#result "Direct link to Result")

```
result = "VS docs API Blog Contribute Community Sponsor v8 *Engishy CV} Q OQ G asearch Next-gen browser and mobile automation Welcome! How can | help? i test framework for Node.js Get Started Why WebdriverI0? View on GitHub Watch on YouTube"
```

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

```
[0-0] 2024-05-25T17:38:25.970Z INFO webdriver: COMMAND ocrGetText()

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

[0-0] 2024-05-25T17:38:26.738Z INFO webdriver: RESULT VS docs API Blog Contribute Community Sponsor v8 *Engishy CV} Q OQ G asearch Next-gen browser and mobile automation Welcome! How can | help? i test framework for Node.js Get Started Why WebdriverI0? View on GitHub Watch on YouTube
```

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

### `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 "Direct link to Example")

```
await browser.ocrGetText({ 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-1 "Direct link to Example")

```
await browser.ocrGetText({ haystack: $("elementSelector") });



// OR

await browser.ocrGetText({ haystack: await $("elementSelector") });



// OR

await browser.ocrGetText({

    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-2 "Direct link to Example")

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

await browser.ocrGetText({

    // Use Dutch as a language

    language: SUPPORTED_OCR_LANGUAGES.DUTCH,

});
```
