LoginSignup
1
0

More than 3 years have passed since last update.

Windows 10 + nodejs + selenium-webdriver + msedgedriver で headless edge(Chromium) を試してみる

Last updated at Posted at 2020-06-14

目的

Edge(Chromium)をnodejs + selenium-webdriver + msedgedriverからキックしてみる
※非同期系の処理は、まだまだだなぁ・・・・

SeleniumBasicのインストール

※環境変数の文字数制限により、同居(笑)
Seleniumbasicの Release page より SeleniumBasic-2.0.9.0.exe をDLする
exeを実行すると、C:\Users\user_name\AppData\Local\SeleniumBasic にインストールされる
ソースコードのプロジェクトをVS2019で開くと .NET Framework 3.5 を指定しているので
Windowsの設定 -> アプリ -> オプション機能 -> Windowsのその他の機能 -> .NET Framework 3.5 が有効であることを確認する

MSEdgeDriver

バージョン情報よりEdgeのバージョンを確認する
今日時点では バージョン 83.0.478.45 (公式ビルド) (64 ビット)
WebDriverよりバージョンに合わせてDLする
edgedriver_win64.zip を解凍後 msedgedriver.exe を SeleniumBasic フォルダに上書する

selenium-webdriverのインストール


> npm install -S selenium-webdriver
+ selenium-webdriver@4.0.0-alpha.7

@microsoft/edge-selenium-toolsのインストール


> npm install @microsoft/edge-selenium-tools

サンプルコード

var edge = require('selenium-webdriver/edge');

let driver;
(async () => {
  try {
        let options = new edge.Options();
        options.setEdgeChromium(true);
        options.setBinaryPath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
        options.addArguments("headless");
        options.addArguments("disable-gpu");

        driver = edge.Driver.createSession(options);
        driver.get("http://www.google.com");

        let html = await driver.getPageSource();
        console.log(html);

    }  catch(error) {
        console.error(error);
    }  finally {
        if(driver) {
            await driver.quit();
        }
    }
})();

参考にしたのは以下のサイト

selenium-webdriver
Module selenium-webdriver
テストオートメーションに WebDriver (Chromium) を使用する
Promiseが分かれば簡単!async, await
Windows 10 + Excel2016 VBA + seleniumbasic で chromedriver / msedgedriver を使ってみる
Selenium Python(ABC順)

1
0
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
1
0