ocrSetValue
Invia una sequenza di tasti a un elemento. Farà:
- rilevare automaticamente l'elemento
- mettere il focus sul campo cliccandoci sopra
- impostare il valore nel campo
Il comando cercherà il testo fornito e tenterà di trovare una corrispondenza basata sulla Logica Fuzzy di Fuse.js. Questo significa che se potresti fornire un selettore con un errore di battitura, o il testo trovato potrebbe non essere una corrispondenza al 100%, cercherà comunque di restituirti un elemento. Guarda i log qui sotto.
Utilizzo
await brower.ocrSetValue({
text: "docs",
value: "specfileretries",
});
Output
Logs
[0-0] 2024-05-26T04:17:51.355Z INFO webdriver: COMMAND ocrSetValue(<object>)
......................
[0-0] 2024-05-26T04:17:52.356Z INFO @wdio/ocr-service:ocrGetElementPositionByText: We searched for the word "docs" and found one match "docs" with score "100%"
Opzioni
text
- Tipo:
string
- Obbligatorio: sì
Il testo che vuoi cercare per cliccare sopra.
Esempio
await browser.ocrSetValue({
text: "WebdriverIO",
value: "The Value",
});
value
- Tipo:
string
- Obbligatorio: sì
Valore da aggiungere.
Esempio
await browser.ocrSetValue({
text: "WebdriverIO",
value: "The Value",
});
submitValue
- Tipo:
boolean
- Obbligatorio: no
- Predefinito:
false
Se il valore deve essere anche inviato nel campo di input. Ciò significa che un "INVIO" verrà inviato alla fine della stringa.
Esempio
await browser.ocrSetValue({
text: "WebdriverIO",
value: "The Value",
submitValue: true,
});
clickDuration
- Tipo:
number
- Obbligatorio: no
- Predefinito:
500
millisecondi
Questa è la durata del clic. Se vuoi puoi anche creare un "clic lungo" aumentando il tempo.
Esempio
await browser.ocrSetValue({
text: "WebdriverIO",
value: "The Value",
clickDuration: 3000, // Questi sono 3 secondi
});
contrast
- Tipo:
number
- Obbligatorio: no
- Predefinito:
0.25
Maggiore è il contrasto, più scura sarà l'immagine e viceversa. Questo può aiutare a trovare testo in un'immagine. Accetta valori tra -1
e 1
.
Esempio
await browser.ocrSetValue({
text: "WebdriverIO",
value: "The Value",
contrast: 0.5,
});
haystack
- Tipo:
number
- Obbligatorio:
WebdriverIO.Element | ChainablePromiseElement | Rectangle
Questa è l'area di ricerca nello schermo in cui l'OCR deve cercare il testo. Può essere un elemento o un rettangolo contenente x
, y
, width
e height
Esempio
await browser.ocrSetValue({
text: "WebdriverIO",
value: "The Value",
haystack: $("elementSelector"),
});
// OPPURE
await browser.ocrSetValue({
text: "WebdriverIO",
value: "The Value",
haystack: await $("elementSelector"),
});
// OPPURE
await browser.ocrSetValue({
text: "WebdriverIO",
value: "The Value",
haystack: {
x: 10,
y: 50,
width: 300,
height: 75,
},
});
language
- Tipo:
string
- Obbligatorio: No
- Predefinito:
eng
La lingua che Tesseract riconoscerà. Maggiori informazioni possono essere trovate qui e le lingue supportate possono essere trovate qui.
Esempio
import { SUPPORTED_OCR_LANGUAGES } from "@wdio/ocr-service";
await browser.ocrSetValue({
text: "WebdriverIO",
value: "The Value",
// Usa l'olandese come lingua
language: SUPPORTED_OCR_LANGUAGES.DUTCH,
});
relativePosition
- Tipo:
object
- Obbligatorio: no
Puoi cliccare sullo schermo in relazione all'elemento corrispondente. Questo può essere fatto in base ai pixel relativi above
, right
, below
o left
dall'elemento corrispondente
Le seguenti combinazioni sono consentite
- proprietà singole
above
+left
oabove
+right
below
+left
obelow
+right
Le seguenti combinazioni NON sono consentite
above
piùbelow
left
piùright
relativePosition.above
- Tipo:
number
- Obbligatorio: no
Clicca x pixel sopra
l'elemento corrispondente.
Esempio
await browser.ocrSetValue({
text: "WebdriverIO",
value: "The Value",
relativePosition: {
above: 100,
},
});