ここのサイト
にも同様の質問がされていますが、
公式のサイトのWebDriverJsを参考にして、Electron上でSeleniumを実行したいのですが、以下のエラーが出てElectronが起動しません。
(node:16636) UnhandledPromiseRejectionWarning: SessionNotCreatedError: session not created: No matching capabilities found at Object.throwDecodedError (/Users/xxx/Desktop/Electron/quick/electron-quick-start/node_modules/selenium-webdriver/lib/error.js:550:15) at parseHttpResponse (/Users/xxx/Desktop/Electron/quick/electron-quick-start/node_modules/selenium-webdriver/lib/http.js:565:13) at Executor.execute (/Users/xxx/Desktop/Electron/quick/electron-quick-start/node_modules/selenium-webdriver/lib/http.js:491:26) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:16636) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:16636) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. (node:16636) UnhandledPromiseRejectionWarning: SessionNotCreatedError: session not created: No matching capabilities found at Object.throwDecodedError (/Users/xxx/Desktop/Electron/quick/electron-quick-start/node_modules/selenium-webdriver/lib/error.js:550:15) at parseHttpResponse (/Users/xxx/Desktop/Electron/quick/electron-quick-start/node_modules/selenium-webdriver/lib/http.js:565:13) at Executor.execute (/Users/xxx/Desktop/Electron/quick/electron-quick-start/node_modules/selenium-webdriver/lib/http.js:491:26) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:16636) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Version
chromium: 85.0.4183.93
Electron: 10.1.1.
ChromeDriver 85.0.4183.84
ソースコードはhttps://github.com/electron/electron-quick-startのmain.jsにseleniumのコードを加えただけです。
導入はhttps://www.electronjs.org/の公式にあるように、
# Quick Start リポジトリを clone する $ git clone https://github.com/electron/electron-quick-start # リポジトリに移動 $ cd electron-quick-start # 依存ライブラリをインストールし、実行 $ npm install $ npm start
に従いました。
なお、seleniumを加えた追加箇所のコード(main.js)は
main.JS
// Modules to control application life and create native browser window const { app, BrowserWindow } = require("electron"); const path = require("path"); const webdriver = require("selenium-webdriver"); function createWindow() { // Create the browser window. const mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { preload: path.join(__dirname, "preload.js"), }, }); // and load the index.html of the app. mainWindow.loadFile("index.html"); // Open the DevTools. // mainWindow.webContents.openDevTools() ///////////////////////////加えたselenium部分////////////////////////////////// const driver = new webdriver.Builder() // The "9515" is the port opened by chrome driver. .usingServer("http://localhost:9515") .withCapabilities({ chromeOptions: { // Here is the path to your Electron binary. binary: "/Users/s_o813/Desktop/Electron/quick/electron-quick-start/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron", }, }) .forBrowser("electron") .build(); driver.get("http://www.google.com"); driver.findElement(webdriver.By.name("q")).sendKeys("webdriver"); driver.findElement(webdriver.By.name("btnG")).click(); driver.wait(() => { return driver.getTitle().then((title) => { return title === "webdriver - Google Search"; }); }, 1000); } ///////////////////////////////////////////////////////////////////////// // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.whenReady().then(() => { createWindow(); app.on("activate", function () { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow(); }); }); // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on("window-all-closed", function () { if (process.platform !== "darwin") app.quit(); }); // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here.
よろしくお願いいたします。
まだ回答がついていません
会員登録して回答してみよう