Skip to main content

ocrSetValue

Send a sequence of key strokes to an element. It will:

  • automatically detect the element
  • put focus on the field by clicking on it
  • set the value in the field

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.ocrSetValue('Username', 'standard_user')

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 ocrSetValue("Usernames", "standard_user")
[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 "Usernames" and found one match "Username" with score "88.89%"

Options#

NameTypeDefaultDetails
selectorstringThe visual name of the field
valuestringValue to be added
options (optional)SetValueOptions{}command options
options.clickDuration (optional)number500Duration of the click in milliseconds
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
options.reuseOcr (optional)booleanfalseRe-use a previous OCR scan if it is available

Example#

it('should set the value of a visible element by using the visible text', () => {
// Set the value
driver.ocrSetValue('Username', 'standard_user')
// OR with options
driver.ocrSetValue(
'Username',
'standard_user',
{
// Same as for iOSRectangles
androidRectangles: {
top: 200,
left: 0,
right: 800,
bottom: 400,
},
reuseOcr: true,
},
)
})