質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Electron

Electronは、HTML5とNode.jsというWebの技術を用いてデスクトップアプリケーションを作成できるクロスプラットフォームな実行環境です。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

Q&A

1回答

3087閲覧

Electron上でseleniumが実行できない。session not created: No matching capabilities found

apeirogon0813

総合スコア117

Electron

Electronは、HTML5とNode.jsというWebの技術を用いてデスクトップアプリケーションを作成できるクロスプラットフォームな実行環境です。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

0グッド

1クリップ

投稿2020/09/11 13:01

編集2020/09/11 13:01

ここのサイト
にも同様の質問がされていますが、

公式のサイトの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

1// Modules to control application life and create native browser window 2const { app, BrowserWindow } = require("electron"); 3const path = require("path"); 4 5 6const webdriver = require("selenium-webdriver"); 7 8function createWindow() { 9 // Create the browser window. 10 const mainWindow = new BrowserWindow({ 11 width: 800, 12 height: 600, 13 webPreferences: { 14 preload: path.join(__dirname, "preload.js"), 15 }, 16 }); 17 18 // and load the index.html of the app. 19 mainWindow.loadFile("index.html"); 20 21 // Open the DevTools. 22 // mainWindow.webContents.openDevTools() 23 24///////////////////////////加えたselenium部分////////////////////////////////// 25 const driver = new webdriver.Builder() 26 // The "9515" is the port opened by chrome driver. 27 .usingServer("http://localhost:9515") 28 .withCapabilities({ 29 chromeOptions: { 30 // Here is the path to your Electron binary. 31 binary: 32 "/Users/s_o813/Desktop/Electron/quick/electron-quick-start/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron", 33 }, 34 }) 35 .forBrowser("electron") 36 .build(); 37 38 driver.get("http://www.google.com"); 39 driver.findElement(webdriver.By.name("q")).sendKeys("webdriver"); 40 driver.findElement(webdriver.By.name("btnG")).click(); 41 driver.wait(() => { 42 return driver.getTitle().then((title) => { 43 return title === "webdriver - Google Search"; 44 }); 45 }, 1000); 46} 47///////////////////////////////////////////////////////////////////////// 48 49// This method will be called when Electron has finished 50// initialization and is ready to create browser windows. 51// Some APIs can only be used after this event occurs. 52app.whenReady().then(() => { 53 createWindow(); 54 55 app.on("activate", function () { 56 // On macOS it's common to re-create a window in the app when the 57 // dock icon is clicked and there are no other windows open. 58 if (BrowserWindow.getAllWindows().length === 0) createWindow(); 59 }); 60}); 61 62// Quit when all windows are closed, except on macOS. There, it's common 63// for applications and their menu bar to stay active until the user quits 64// explicitly with Cmd + Q. 65app.on("window-all-closed", function () { 66 if (process.platform !== "darwin") app.quit(); 67}); 68 69// In this file you can include the rest of your app's specific main process 70// code. You can also put them in separate files and require them here. 71

よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

やりたいことの趣旨からは外れるかもしれませんが、こちらを使うとelectronのBrowserWindowを一つ立てて、Seleniumが走ります。
https://www.npmjs.com/package/puppeteer-in-electron

すでにあるelectronアプリに組み込む場合は、こちらが参考になりますが、
https://officeforest.org/wp/2020/02/26/electron%E3%81%A7puppeteer%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%81%BF%E3%82%8B%E3%81%93%E3%81%A8%E3%81%AB%E3%81%97%E3%81%9F/

こちらのサイト制作者の方はNPM公式にある

js

1await pie.initialize(app); 2const browser = await pie.connect(app, puppeteer);

pie.initialize(app)を書き忘れているらしくエラーが出ます。

ご注意ください。

投稿2020/12/06 10:01

quadii.shii

総合スコア257

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問