3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nodejs selenium でページ全体をスクショする

3
Last updated at Posted at 2019-05-30

npm init
npm i -S selenium-webdriver

https://github.com/SeleniumHQ/selenium/tree/master/javascript/node/selenium-webdriver#installation
からdriverをインストール

今回はchrome 74

PATHを通す

export PATH=${DOWNLOADED_CHROME_DRIVER}:$PATH
index.js
const { Builder } = require('selenium-webdriver');
const fs = require('fs');

(async () => {
  
  const driver = await new Builder()
    .forBrowser('chrome')
    .setChromeOptions([
      '--headless',
      '--disable-gpu',
    ])
    .build();

  try {
    await driver.get('http://www.google.com');
    const base64 = await driver.takeScreenshot();
    const buffer = Buffer.from(base64, 'base64');
    fs.writeFileSync('screenshot.jpg', buffer);
  } catch (e) {
    console.log(e)
  } finally {
    await driver.quit();
  }
})();
node index.js

nodeでdom要素のみのスクショはまだできないっぽいです

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?