跳至主要内容

ocrGetText

获取图像上的文本。

用法

const result = await browser.ocrGetText();

console.log("result = ", JSON.stringify(result, null, 2));

输出

结果

result = "VS docs API Blog Contribute Community Sponsor v8 *Engishy CV} Q OQ G asearch Next-gen browser and mobile automation Welcome! How can | help? i test framework for Node.js Get Started Why WebdriverI0? View on GitHub Watch on YouTube"

日志

[0-0] 2024-05-25T17:38:25.970Z INFO webdriver: COMMAND ocrGetText()
......................
[0-0] 2024-05-25T17:38:26.738Z INFO webdriver: RESULT VS docs API Blog Contribute Community Sponsor v8 *Engishy CV} Q OQ G asearch Next-gen browser and mobile automation Welcome! How can | help? i test framework for Node.js Get Started Why WebdriverI0? View on GitHub Watch on YouTube

选项

contrast

  • 类型: number
  • 必填:
  • 默认值: 0.25

对比度越高,图像越暗,反之亦然。这可以帮助在图像中找到文本。它接受介于-11之间的值。

示例

await browser.ocrGetText({ contrast: 0.5 });

haystack

  • 类型: number
  • 必填: WebdriverIO.Element | ChainablePromiseElement | Rectangle

这是屏幕上OCR需要查找文本的搜索区域。这可以是一个元素或一个包含xywidthheight的矩形

示例

await browser.ocrGetText({ haystack: $("elementSelector") });

// OR
await browser.ocrGetText({ haystack: await $("elementSelector") });

// OR
await browser.ocrGetText({
haystack: {
x: 10,
y: 50,
width: 300,
height: 75,
},
});

language

  • 类型: string
  • 必填:
  • 默认值: eng

Tesseract将识别的语言。更多信息可以在这里找到这里,支持的语言可以在这里找到这里

示例

import { SUPPORTED_OCR_LANGUAGES } from "@wdio/ocr-service";
await browser.ocrGetText({
// Use Dutch as a language
language: SUPPORTED_OCR_LANGUAGES.DUTCH,
});

欢迎!我怎样才能帮助您?

WebdriverIO AI Copilot