ocrGetElementPositionByText
화면에서 텍스트의 위치를 가져옵니다. 이 명령은 제공된 텍스트를 검색하고 Fuse.js의 퍼지 로직을 기반으로 일치하는 항목을 찾으려고 시도합니다. 이는 선택자에 오타가 있거나 찾은 텍스트가 100% 일치하지 않더라도 여전히 요소를 반환하려고 시도한다는 것을 의미합니다. 아래 로그를 참조하세요.
사용법
const result = await browser.ocrGetElementPositionByText("Username");
console.log("result = ", JSON.stringify(result, null, 2));
출력
결과
result = {
"dprPosition": {
"left": 373,
"top": 606,
"right": 439,
"bottom": 620
},
"filePath": ".tmp/ocr/desktop-1716658199410.png",
"matchedString": "Started",
"originalPosition": {
"left": 373,
"top": 606,
"right": 439,
"bottom": 620
},
"score": 85.71,
"searchValue": "Start3d"
}
로그
# "Start3d"를 검색했지만 찾은 텍스트가 "Started"였음에도 일치 항목을 찾았습니다
[0-0] 2024-05-25T17:29:59.179Z INFO webdriver: COMMAND ocrGetElementPositionByText(<object>)
......................
[0-0] 2024-05-25T17:29:59.993Z INFO @wdio/ocr-service:ocrGetElementPositionByText: Multiple matches were found based on the word "Start3d". The match "Started" with score "85.71%" will be used.
옵션
text
- 타입:
string - 필수: 예
클릭하기 위해 검색하려는 텍스트입니다.
예시
await browser.ocrGetElementPositionByText({ text: "WebdriverIO" });
contrast
- 타입:
number - 필수: 아니오
- 기본값:
0.25
대비가 높을수록 이미지가 어두워지고 그 반대도 마찬가지입니다. 이는 이미지에서 텍스트를 찾는 데 도움이 될 수 있습니다. -1과 1 사이의 값을 허용합니다.
예시
await browser.ocrGetElementPositionByText({
text: "WebdriverIO",
contrast: 0.5,
});
haystack
- 타입:
number - 필수:
WebdriverIO.Element | ChainablePromiseElement | Rectangle
OCR이 텍스트를 찾아야 하는 화면의 검색 영역입니다. 이는 요소이거나 x, y, width, height를 포함하는 직사각형일 수 있습니다.
예시
await browser.ocrGetElementPositionByText({
text: "WebdriverIO",
haystack: $("elementSelector"),
});
// 또는
await browser.ocrGetElementPositionByText({
text: "WebdriverIO",
haystack: await $("elementSelector"),
});
// 또는
await browser.ocrGetElementPositionByText({
text: "WebdriverIO",
haystack: {
x: 10,
y: 50,
width: 300,
height: 75,
},
});
language
- 타입:
string - 필수: 아니오
- 기본값:
eng
Tesseract가 인식할 언어입니다. 자세한 정보는 여기에서 찾을 수 있으며 지원되는 언어는 여기에서 확인할 수 있습니다.