diff --git a/playwriter/src/aria-snapshot.ts b/playwriter/src/aria-snapshot.ts index d043d0d..f22ece5 100644 --- a/playwriter/src/aria-snapshot.ts +++ b/playwriter/src/aria-snapshot.ts @@ -207,16 +207,18 @@ function toAttributeMap(attributes?: string[]): Map { } function getStableRefFromAttributes(attributes: Map): { value: string; attr: string } | null { - const id = attributes.get('id') - if (id) { - return { value: id, attr: 'id' } - } + // Test IDs first: they are explicitly placed by developers for automation + // and more stable than id which is often auto-generated by frameworks for (const attr of TEST_ID_ATTRS) { const value = attributes.get(attr) if (value) { return { value, attr } } } + const id = attributes.get('id') + if (id) { + return { value: id, attr: 'id' } + } return null }