@@ -1017,7 +1017,7 @@ export class DeviceWrapper {
1017
1017
// Find all candidate elements matching the locator
1018
1018
const elements = await this . findElements ( locator . strategy , locator . selector ) ;
1019
1019
this . info (
1020
- `[matchAndTapImage] Found ${ elements . length } elements for ${ locator . strategy } "${ locator . selector } "`
1020
+ `[matchAndTapImage] Starting image matching: ${ elements . length } elements with ${ locator . strategy } "${ locator . selector } "`
1021
1021
) ;
1022
1022
1023
1023
// Load the reference image buffer from disk
@@ -1030,8 +1030,7 @@ export class DeviceWrapper {
1030
1030
} | null = null ;
1031
1031
1032
1032
// Iterate over each candidate element
1033
- for ( const [ i , el ] of elements . entries ( ) ) {
1034
- this . info ( `[matchAndTapImage] Processing element ${ i + 1 } /${ elements . length } ` ) ;
1033
+ for ( const el of elements ) {
1035
1034
1036
1035
// Take a screenshot of the element
1037
1036
const base64 = await this . getElementScreenshot ( el . ELEMENT ) ;
@@ -1064,7 +1063,6 @@ export class DeviceWrapper {
1064
1063
const { rect : matchRect , score } = await getImageOccurrence ( elementBuffer , resizedRef , {
1065
1064
threshold,
1066
1065
} ) ;
1067
- this . info ( `[matchAndTapImage] Match score for element ${ i + 1 } : ${ score . toFixed ( 4 ) } ` ) ;
1068
1066
1069
1067
/**
1070
1068
* Matching is done on a resized reference image to account for device pixel density.
@@ -1097,29 +1095,25 @@ export class DeviceWrapper {
1097
1095
// If earlyMatch is enabled and the score is high enough, tap immediately
1098
1096
if ( earlyMatch && score >= earlyMatchThreshold ) {
1099
1097
this . info (
1100
- `[matchAndTapImage] Tapping first match with ${ ( score * 100 ) . toFixed ( 2 ) } % confidence `
1098
+ `[matchAndTapImage] Tapping first high-confidence match ( ${ ( score * 100 ) . toFixed ( 2 ) } %) `
1101
1099
) ;
1102
1100
await clickOnCoordinates ( this , center ) ;
1103
1101
return ;
1104
1102
}
1105
1103
// Otherwise, keep track of the best match so far
1106
1104
if ( ! bestMatch || score > bestMatch . score ) {
1107
1105
bestMatch = { center, score } ;
1108
- this . info ( `[matchAndTapImage] New best match: ${ ( score * 100 ) . toFixed ( 2 ) } % confidence` ) ;
1109
1106
}
1110
- } catch ( err ) {
1111
- // If matching fails for this element, log and continue to the next
1112
- this . info (
1113
- `[matchAndTapImage] Matching failed for element ${ i + 1 } :` ,
1114
- err instanceof Error ? err . message : err
1115
- ) ;
1107
+ } catch {
1108
+ continue ; // No match in this element, try next
1116
1109
}
1117
1110
}
1118
1111
// If no good match was found, throw an error
1119
1112
if ( ! bestMatch ) {
1120
- throw new Error (
1113
+ console . log (
1121
1114
`[matchAndTapImage] No matching image found among ${ elements . length } elements for ${ locator . strategy } "${ locator . selector } "`
1122
1115
) ;
1116
+ throw new Error ( 'Unable to find the expected UI element on screen' ) ;
1123
1117
}
1124
1118
// Tap the best match found
1125
1119
this . info (
0 commit comments