From 03c57bbcb89afe5473d9dadd52b0a8a6896dee46 Mon Sep 17 00:00:00 2001 From: Harshit Date: Tue, 29 Oct 2024 15:23:04 +0530 Subject: [PATCH] issue - #3655 frame() command doesn't support page object element #3655. github- harshit-7373 --- lib/api/protocol/frame.js | 13 +++++++++++-- types/index.d.ts | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/api/protocol/frame.js b/lib/api/protocol/frame.js index 07f5f53ca..0a9666c43 100644 --- a/lib/api/protocol/frame.js +++ b/lib/api/protocol/frame.js @@ -28,7 +28,6 @@ const ProtocolAction = require('./_base-action.js'); * @api protocol.frames */ const findElement = function(selector) { - return new Promise((resolve, reject) => { this.api.findElement({selector, suppressNotFoundErrors: true}, function(res) { if (res.status === -1 && res.error) { @@ -52,7 +51,17 @@ module.exports = class Session extends ProtocolAction { return this.transportActions.switchToFrame(callback); } - if (typeof frameId == 'string') { + // Check if frameId is a page object element by checking if it starts with "@" + if (typeof frameId === 'string' && frameId.startsWith('@')) { + // Resolve the page object selector to an actual CSS selector + frameId = await this.api.resolveElement(frameId) + .catch(err => { + throw new Error(`Unable to resolve page object selector ${frameId}.`); + }); + } + + // Proceed with finding the frame element using the resolved selector + if (typeof frameId === 'string') { frameId = await findElement.call(this, frameId) .catch(err => { return findElement.call(this, `*[name="${frameId}"]`); diff --git a/types/index.d.ts b/types/index.d.ts index 2d7254ec5..e85511197 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -7950,4 +7950,4 @@ declare global { const ensure: Ensure; const expect: Expect; const locateWith: typeof seleniumLocateWith; -} +} \ No newline at end of file