Skip to content

Commit bb425c2

Browse files
committed
fix: Puppeteer grabAttributeFrom and XPath click issues
- Remove jsonValue() call in grabAttributeFromAll (Puppeteer 24.x returns values directly) - Fix XPath selector to work with all matcher types (Page/Frame/ElementHandle) - Use try/catch for ::-p-xpath() selector with fallback for ElementHandles
1 parent 3a61c6f commit bb425c2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/helper/Puppeteer.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ class Puppeteer extends Helper {
20822082
const array = []
20832083
for (let index = 0; index < els.length; index++) {
20842084
const a = await this._evaluateHandeInContext((el, attr) => el[attr] || el.getAttribute(attr), els[index], attr)
2085-
array.push(await a.jsonValue())
2085+
array.push(a)
20862086
}
20872087
return array
20882088
}
@@ -2887,12 +2887,16 @@ async function findElements(matcher, locator) {
28872887
}
28882888

28892889
// For Puppeteer 24.x+, $x method was removed
2890-
// Use ::-p-xpath() selector syntax for Page/Frame
2891-
const matcherType = matcher.constructor?.name
2892-
if (matcherType === 'CdpPage' || matcherType === 'CdpFrame') {
2893-
// matcher is Page or Frame - use ::-p-xpath selector
2890+
// Use ::-p-xpath() selector syntax
2891+
// Check if matcher has $$ method (Page, Frame, or ElementHandle)
2892+
if (matcher && typeof matcher.$$ === 'function') {
28942893
const xpathSelector = `::-p-xpath(${locator.value})`
2895-
return matcher.$$(xpathSelector)
2894+
try {
2895+
return await matcher.$$(xpathSelector)
2896+
} catch (e) {
2897+
// XPath selector may not work on ElementHandle, fall through to evaluate method
2898+
this.debug && this.debug(`XPath selector failed on ${matcher.constructor?.name}: ${e.message}`)
2899+
}
28962900
}
28972901

28982902
// ElementHandles don't support XPath directly // Search within the element by making XPath relative

0 commit comments

Comments
 (0)