Option />'
+
+ const map = getElementTextMap(simplifiedHTML)
+
+ expect(map.get(3)).toBe('*[3]
Option />')
+ })
+})
diff --git a/packages/page-controller/src/dom/index.ts b/packages/page-controller/src/dom/index.ts
index a7ae7f8ee..99e4f711e 100644
--- a/packages/page-controller/src/dom/index.ts
+++ b/packages/page-controller/src/dom/index.ts
@@ -514,7 +514,8 @@ export function getElementTextMap(simplifiedHTML: string) {
.filter((line) => line.length > 0)
const elementTextMap = new Map
()
for (const line of lines) {
- const regex = /^\[(\d+)\]<[^>]+>([^<]*)/
+ // New elements are prefixed with '*' (e.g. `*[5]]+>([^<]*)/
const match = regex.exec(line)
if (match) {
const index = parseInt(match[1], 10)