import { Frame } from "https://deno.land/x/frugal@0.9.6/dep/puppeteer/mod.ts";
Represents a DOM frame.
To understand frames, you can think of frames as <iframe>
elements. Just
like iframes, frames can be nested, and when JavaScript is executed in a
frame, the JavaScript does not effect frames inside the ambient frame the
JavaScript executes in.
Examples
At any point in time, Page | pages expose their current frame
tree via the Page.mainFrame and Frame.childFrames methods.
At any point in time, Page | pages expose their current frame tree via the Page.mainFrame and Frame.childFrames methods.
An example of dumping frame tree:
An example of dumping frame tree:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.google.com/chrome/browser/canary.html');
dumpFrameTree(page.mainFrame(), '');
await browser.close();
function dumpFrameTree(frame, indent) {
console.log(indent + frame.url());
for (const child of frame.childFrames()) {
dumpFrameTree(child, indent + ' ');
}
}
})();
An example of getting text from an iframe element:
An example of getting text from an iframe element:
const frame = page.frames().find(frame => frame.name() === 'myframe');
const text = await frame.$eval('.selector', element => element.textContent);
console.log(text);
Constructors
Properties
Methods
Queries the frame for an element matching the given selector.
Queries the frame for all elements matching the given selector.
Runs the given function on an array of elements matching the given selector in the frame.
If the given function returns a promise, then this method will wait till the promise resolves.
Runs the given function on the first element matching the given selector in the frame.
If the given function returns a promise, then this method will wait till the promise resolves.
Adds a <script>
tag into the page with the desired url or content.
Adds a <link rel="stylesheet">
tag into the page with the desired url or
a <style type="text/css">
tag with the content.
Clicks the first element found that matches selector
.
Behaves identically to Page.evaluate except it's run within the the context of this frame.
Behaves identically to Page.evaluateHandle except it's run within the context of this frame.
Focuses the first element that matches the selector
.
Navigates a frame to the given url.
Hovers the pointer over the center of the first element that matches the
selector
.
Selects a set of value on the first <select>
element that matches the
selector
.
Set the content of the frame.
Taps the first element that matches the selector
.
Sends a keydown
, keypress
/input
, and keyup
event for each character
in the text.
Waits for an element matching the given selector to appear in the frame.
This method works across navigations.