puppeteer-extra-commands

Some useful commands for puppeteer


Keywords
puppeteer
License
Unlicense
Install
npm install puppeteer-extra-commands@2.2.20

Documentation

Tiny library with additional puppeteer commands

Use commands this way:

const puppeteer = require('puppeteer');
const p = require('puppeteer-extra-commands');

(async () => {
    const browser = await puppeteer.launch();
    const [page] = await browser.pages();

    await page.goto('http://example.com');
    const [text] = await p.getTextContent(page, 'h1'); // 'Example Domain'
    const [prop] = await p.getCssProperty(page, 'h1', 'font-size'); // '32px'
    const [href] = await p.getAttribute(page, 'a', 'href'); // 'http://www.iana.org/domains/example'

    await browser.close();
})();

All available commands:

clickForNavigation
fillForm
getAttribute
getCssProperty
getTextContent
getWindowOffset
saveScreenshot
scrollWindowBy
switchToFrameIncludes

A little more abstract examples:

const frame = await p.switchToFrameIncludes(page, 'url', 'mysite.hello.com/iframe.html');
const text = await p.getTextContent(frame, '.titles'); // ['title1', 'title2', 'title3']
// ...
const frame = await p.switchToFrameIncludes(page, 'name', 'auth');
await p.scrollWindowBy(frame, {y: 100});
const newPosition = await p.getWindowOffset(frame); // {x: 0; y: 100}
// ...
await p.fillForm(page, [
    {field: '.login', text: 'maggy1998'},
    {field: '.password', text: 'flower'},
    {click: '.button'},
]);

Tests

# run all
npm run test

# or one test
npm run one-test --test=getText

# disable headless mode
npm run one-test --test=getText --show