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.