Skip to content

Commit f629d6f

Browse files
DavertMikclaude
andcommitted
fix: improve shadow DOM support and fix iframe error message in Playwright
- Chain locators for shadow DOM instead of using >>> combinator - Fix iframe error message to say "Element" instead of "Frame" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4f86c34 commit f629d6f

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lib/helper/Playwright.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3568,7 +3568,7 @@ class Playwright extends Helper {
35683568
}
35693569

35703570
if (!frame) {
3571-
throw new Error(`Frame ${JSON.stringify(locator)} was not found by text|CSS|XPath`)
3571+
throw new Error(`Element ${JSON.stringify(locator)} was not found by text|CSS|XPath`)
35723572
}
35733573

35743574
try {
@@ -4149,6 +4149,21 @@ async function findElements(matcher, locator) {
41494149

41504150
locator = new Locator(locator, 'css')
41514151

4152+
if (locator.isShadow()) {
4153+
const shadowPath = locator.value
4154+
let currentMatcher = matcher
4155+
4156+
for (let i = 0; i < shadowPath.length - 1; i++) {
4157+
const elementSelector = shadowPath[i]
4158+
currentMatcher = currentMatcher.locator(elementSelector)
4159+
const element = await currentMatcher.first()
4160+
currentMatcher = element
4161+
}
4162+
4163+
const finalSelector = shadowPath[shadowPath.length - 1]
4164+
return currentMatcher.locator(finalSelector).all()
4165+
}
4166+
41524167
const locatorString = buildLocatorString(locator)
41534168

41544169
return matcher.locator(locatorString).all()
@@ -4161,6 +4176,21 @@ async function findElement(matcher, locator) {
41614176

41624177
locator = new Locator(locator, 'css')
41634178

4179+
if (locator.isShadow()) {
4180+
const shadowPath = locator.value
4181+
let currentMatcher = matcher
4182+
4183+
for (let i = 0; i < shadowPath.length - 1; i++) {
4184+
const elementSelector = shadowPath[i]
4185+
currentMatcher = currentMatcher.locator(elementSelector)
4186+
const element = await currentMatcher.first()
4187+
currentMatcher = element
4188+
}
4189+
4190+
const finalSelector = shadowPath[shadowPath.length - 1]
4191+
return currentMatcher.locator(finalSelector).first()
4192+
}
4193+
41644194
return matcher.locator(buildLocatorString(locator)).first()
41654195
}
41664196

0 commit comments

Comments
 (0)