Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
frame() command doesn't support page object element nightwatchjs#3655.

github- harshit-7373
  • Loading branch information
Harshit-7373 committed Oct 29, 2024
1 parent 0e0fb2c commit 03c57bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/api/protocol/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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}"]`);
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7950,4 +7950,4 @@ declare global {
const ensure: Ensure;
const expect: Expect;
const locateWith: typeof seleniumLocateWith;
}
}

0 comments on commit 03c57bb

Please sign in to comment.