ocrWaitForTextDisplayed
Wait for a specific text to be displayed on the screen.
Usage
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries",
});
Output
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
text
- Type:
string - Mandatory: yes
The text you want to search for to click on.
Example
await browser.ocrWaitForTextDisplayed({ text: "specFileRetries" });
timeout
- Type:
number - Mandatory: no
- Default: 18000 (18 seconds)
Time in milliseconds. Be aware that the OCR process can take some time, so don't set it too low.
Example
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries"
timeout: 25000 // wait for 25 seconds
});
timeoutMsg
- Type:
string - Mandatory: no
- Default:
Could not find the text "{selector}" within the requested time.
It overrides the default error message.
Example
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries"
timeoutMsg: "My new timeout message."
});
contrast
- Type:
number - Mandatory: no
- Default:
0.25
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
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries",
contrast: 0.5,
});
haystack
- Type:
number - Mandatory:
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
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
- Type:
string - Mandatory: No
- Default:
eng
The language that Tesseract will recognize. More info can be found here and the supported languages can be found here.
Example
import { SUPPORTED_OCR_LANGUAGES } from "@wdio/ocr-service";
await browser.ocrWaitForTextDisplayed({
text: "specFileRetries",
// Use Dutch as a language
language: SUPPORTED_OCR_LANGUAGES.DUTCH,
});