Skip to main content

ocrClickOnText

Click on an element based on the provided texts. The command will search for the provided text and tries to find a match based on Fuzzy Logic from Fuse.js. This means that if you might provide a selector with a typo, or the found text might not be a 100% match it will still try to give you back an element. See the logs below.

Usage#

driver.ocrClickOnText('Login')

Logs#

# Still finding a match even though we searched for "Usernames" and the found text was "Username"
[0-0] 2021-04-07T09:51:07.806Z INFO webdriver: COMMAND ocrClickOnText("Logins")
[0-0] 2021-04-07T09:51:07.807Z INFO webdriver: RESULT true
[0-0] 2021-04-07T09:51:07.811Z INFO wdio-ocr-service: We searched for the word "Logins" and found one match "Login" with score "88.89%"

Options#

NameTypeDefaultDetails
selectorstringThe visual name of the field
options (optional)SetValueOptions{}command options
options.clickDuration (optional)number500Duration of the click in milliseconds
options.reuseOcr (optional)booleanfalseRe-use a previous OCR scan if it is available
options.androidRectangles (optional)RectanglesRectangles for Android to crop the search area for OCR
options.androidRectangles.topnumberStart position from the top of the screen to start cropping the search area for OCR
options.androidRectangles.leftnumberStart position from the left of the screen to start cropping the search area for OCR
options.androidRectangles.rightnumberStart position from the right of the screen to start cropping the search area for OCR
options.androidRectangles.bottomnumberStart position from the bottom of the screen to start cropping the search area for OCR
options.iOSRectangles (optional)RectanglesRectangles for Android to crop the search area for OCR
options.iOSRectangles.topnumberStart position from the top of the screen to start cropping the search area for OCR
options.iOSRectangles.leftnumberStart position from the left of the screen to start cropping the search area for OCR
options.iOSRectangles.rightnumberStart position from the right of the screen to start cropping the search area for OCR
options.iOSRectangles.bottomnumberStart position from the bottom of the screen to start cropping the search area for OCR

Example#

it('should click on an element based on text', () => {
// Click on text
driver.ocrClickOnText('Login')
// OR with options
driver.ocrClickOnText(
'Login',
{
// Same as for iOSRectangles
androidRectangles: {
top: 200,
left: 0,
right: 800,
bottom: 400,
},
reuseOcr: true,
},
)
})