webdriverio-automation
Version:
WebdriverIO-Automation android ios project
59 lines (43 loc) • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = switchToFrame;
var _constants = require("../constants");
var _utils = require("../utils");
async function switchToFrame({
id
}) {
const page = this.getPageHandle(true);
if (id === null && typeof page.parentFrame === 'function') {
let parentFrame = await page.parentFrame();
while (parentFrame) {
parentFrame = await parentFrame.parentFrame();
}
this.currentFrame = parentFrame;
return null;
}
if (typeof id[_constants.ELEMENT_KEY] === 'string') {
const elementHandle = this.elementStore.get(id[_constants.ELEMENT_KEY]);
if (!elementHandle) {
throw (0, _utils.getStaleElementError)(elementHandle);
}
const contentFrame = await elementHandle.contentFrame();
if (!contentFrame) {
throw new Error('no such frame');
}
this.currentFrame = contentFrame;
return null;
}
if (typeof id === 'number') {
let getFrames = page.frames || page.childFrames;
const childFrames = await getFrames.apply(page);
const childFrame = childFrames[id];
if (!childFrame) {
throw new Error('no such frame');
}
this.currentFrame = childFrame;
return null;
}
throw new Error(`Could not switch frame, unknwon id: ${id}`);
}