2
1

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 3 years have passed since last update.

selenium-webdriverがWebpack環境下で動かない問題

Posted at

現象

Vue Cli 3 + Vue CLI Plugin Electron Builder環境でselenium-webdriverを使用した場合、次のようなエラーがでる。
Uncaught Error: Failed to import atoms module ./atoms/get-attribute.js. If running in dev mode, you need to run `bazel build //javascript/node/selenium-webdriver/lib/atoms:get-attribute.js` from the projectroot: Error: Cannot find module './atoms/get-attribute.js'

結論

node_modules/selenium-webdriver/lib/http.jsを次のように修正する。

  • requireAtomを実行している部分の第一引数をファイル名だけにする
  • requireAtom関数内でrequireしている部分にpathを追加する

修正前

const getAttribute = requireAtom(
    './atoms/get-attribute.js',
    '//javascript/node/selenium-webdriver/lib/atoms:get-attribute.js');
const isDisplayed = requireAtom(
    './atoms/is-displayed.js',
    '//javascript/node/selenium-webdriver/lib/atoms:is-displayed.js');
/**
 * @param {string} module
 * @param {string} bazelTarget
 * @return {!Function}
 */
function requireAtom(module, bazelTarget) {
  try {
    return require(module);
  } catch (ex) {
    ...
  }
}

修正後

const getAttribute = requireAtom(
    'get-attribute.js',
    '//javascript/node/selenium-webdriver/lib/atoms:get-attribute.js');
const isDisplayed = requireAtom(
    'is-displayed.js',
    '//javascript/node/selenium-webdriver/lib/atoms:is-displayed.js');
/**
 * @param {string} module
 * @param {string} bazelTarget
 * @return {!Function}
 */
function requireAtom(module, bazelTarget) {
  try {
    return require('./atoms/' + module);
  } catch (ex) {
    ...
  }
}

このように修正すると無事requireされて実行できます。

余談

ワクワクしてプルリクだそうとしたら先客がいました。くやしいぃ・・・
https://github.com/SeleniumHQ/selenium/pull/7726

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?