Skip to content

Commit 23ffd50

Browse files
Copilotkobenguyent
andcommitted
Changes before error encountered
Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com>
1 parent e1a9cc6 commit 23ffd50

File tree

1 file changed

+8
-54
lines changed

1 file changed

+8
-54
lines changed

lib/helper/Puppeteer.js

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,51 +2729,17 @@ class Puppeteer extends Helper {
27292729
module.exports = Puppeteer
27302730

27312731
/**
2732-
* Build locator string for Puppeteer's Locator API
2733-
* Similar to Playwright's buildLocatorString function for consistency
2734-
* @param {Locator} locator - CodeceptJS Locator object
2735-
* @returns {string} Locator string compatible with Puppeteer's locator() method
2736-
*/
2737-
function buildLocatorString(locator) {
2738-
if (locator.isCustom()) {
2739-
return `${locator.type}=${locator.value}`
2740-
}
2741-
if (locator.isXPath()) {
2742-
return `xpath=${locator.value}`
2743-
}
2744-
return locator.simplify()
2745-
}
2746-
2747-
/**
2748-
* Find elements using Puppeteer's modern Locator API with ElementHandle fallback
2749-
* This provides better reliability and waiting behavior while maintaining backward compatibility
2732+
* Find elements using Puppeteer's native element discovery methods
2733+
* Note: Unlike Playwright, Puppeteer's Locator API doesn't have .all() method for multiple elements
27502734
* @param {Page|Frame|ElementHandle} matcher - Puppeteer context to search within
27512735
* @param {Object|string} locator - Locator specification
2752-
* @returns {Promise<ElementHandle[]>} Array of ElementHandle objects for compatibility
2736+
* @returns {Promise<ElementHandle[]>} Array of ElementHandle objects
27532737
*/
27542738
async function findElements(matcher, locator) {
27552739
if (locator.react) return findReactElements.call(this, locator)
27562740
locator = new Locator(locator, 'css')
27572741

2758-
// Use Locator API for better reliability, then convert to ElementHandles for compatibility
2759-
if (matcher.locator) {
2760-
const locatorElement = matcher.locator(buildLocatorString(locator))
2761-
const handles = await locatorElement.all()
2762-
// Convert Locator elements to ElementHandles for backward compatibility
2763-
return Promise.all(
2764-
handles.map(async handle => {
2765-
// For Puppeteer Locators, we can get ElementHandle using waitHandle()
2766-
try {
2767-
return await handle.waitHandle()
2768-
} catch (e) {
2769-
// Fallback for edge cases
2770-
return handle
2771-
}
2772-
}),
2773-
)
2774-
}
2775-
2776-
// Fallback to legacy approach if Locator not available
2742+
// Use proven legacy approach - Puppeteer Locator API doesn't have .all() method
27772743
if (!locator.isXPath()) return matcher.$$(locator.simplify())
27782744
// puppeteer version < 19.4.0 is no longer supported. This one is backward support.
27792745
if (puppeteer.default?.defaultBrowserRevision) {
@@ -2783,29 +2749,17 @@ async function findElements(matcher, locator) {
27832749
}
27842750

27852751
/**
2786-
* Find a single element using Puppeteer's modern Locator API with ElementHandle fallback
2752+
* Find a single element using Puppeteer's native element discovery methods
2753+
* Note: Puppeteer Locator API doesn't have .first() method like Playwright
27872754
* @param {Page|Frame|ElementHandle} matcher - Puppeteer context to search within
27882755
* @param {Object|string} locator - Locator specification
2789-
* @returns {Promise<ElementHandle>} Single ElementHandle object for compatibility
2756+
* @returns {Promise<ElementHandle>} Single ElementHandle object
27902757
*/
27912758
async function findElement(matcher, locator) {
27922759
if (locator.react) return findReactElements.call(this, locator)
27932760
locator = new Locator(locator, 'css')
27942761

2795-
// Use Locator API for better reliability, then get first ElementHandle for compatibility
2796-
if (matcher.locator) {
2797-
const locatorElement = matcher.locator(buildLocatorString(locator))
2798-
const handle = await locatorElement.first()
2799-
// Convert to ElementHandle for backward compatibility
2800-
try {
2801-
return await handle.waitHandle()
2802-
} catch (e) {
2803-
// Fallback for edge cases
2804-
return handle
2805-
}
2806-
}
2807-
2808-
// Fallback to legacy approach if Locator not available
2762+
// Use proven legacy approach - Puppeteer Locator API doesn't have .first() method
28092763
if (!locator.isXPath()) {
28102764
const elements = await matcher.$$(locator.simplify())
28112765
return elements[0]

0 commit comments

Comments
 (0)