selenium-webdriver - 如何使用 NPM 更新适用于 Windows 的 ChromeDriver?

标签 selenium-webdriver npm selenium-chromedriver

在 Windows 上,我正在尝试更新 ChromeDriver 以利用 Chrome 的新 headless 选项。不过,更新完成后,ChromeDriver 就会恢复到之前的版本。

在下面命令提示符的控制台日志中,您可以看到我下载的是2.33版本,但最后我得到的版本是2.27。我至少需要 2.29 才能使用 headless Chrome。

C:\WINDOWS\system32>npm uninstall chromedriver
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a5a434c536a180419041a" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\globby\node_modules\pify
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a2d26252828330a7c647b647a" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\globby
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b9d0cad8cbcbd8c0f98897899789" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\isarray
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e78a8e898e8a8e9493a7d7c9d7c9df" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\minimist
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c717778756e6c5c2c3229322c" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\extract-zip\node_modules\mkdirp
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="28455b681a06180618" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\ms
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="096d6c6b7c6e493b273f2730" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\debug
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="41316c2c203101706f736f71" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\p-map
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b1b0e050f2b5a4559455b" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\pend
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ee8eaa3fde2e7edebfccebfa0bea0bf" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\fd-slicer
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9bebf2fde2dba8b5abb5ab" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\pify
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="16666479757365653b78736e627f757d3b77647165562738263821" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\process-nextick-args
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0b3b4b2a9aea79fa4a5a3afa4a5b280f1eef0eef3" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\string_decoder
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cfbbb6bfaaabaebdbdaeb68fffe1ffe1f9" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\typedarray
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b4e4f5257165f5e4b495e585a4f5e7b0a150b1509" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\util-deprecate
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fb899e9a9f9a99979ed6888f899e9a96bbc9d5c8d5c8" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\readable-stream
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f7949899949683da84838592969ab7c6d9c1d9c7" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\concat-stream
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bac3dbcfc0d6fa88948e948b" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\yauzl
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e387868fa3d0cdd3cdd3" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\del
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bbdec3cfc9dad8cf96c1d2cbfb8a958d958d" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\extract-zip
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6d06081a2d5d435a435d" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\kew
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ef3f5faf7eceedeaeb0abb0af" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\mkdirp
- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdded5cfd2d0d8d9cfd4cbd8cffd8f938e8e938f" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\chromedriver
npm WARN enoent ENOENT: no such file or directory, open 'C:\WINDOWS\system32\package.json'
npm WARN system32 No description
npm WARN system32 No repository field.
npm WARN system32 No README data
npm WARN system32 No license field.

C:\WINDOWS\system32>npm install chromedriver

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8dbd0cad7d5dddccad1ceddcaf88a968b8b968a" rel="noreferrer noopener nofollow">[email protected]</a> install C:\WINDOWS\system32\node_modules\chromedriver
> node install.js

Downloading https://chromedriver.storage.googleapis.com/2.33/chromedriver_win32.zip
Saving to C:\Users\vadmin\AppData\Local\Temp\chromedriver\chromedriver_win32.zip
Received 781K...
Received 1568K...
Received 2352K...
Received 3136K...
Received 3920K...
Received 4125K total.
Extracting zip contents
Copying to target path C:\WINDOWS\system32\node_modules\chromedriver\lib\chromedriver
Done. ChromeDriver binary available at C:\WINDOWS\system32\node_modules\chromedriver\lib\chromedriver\chromedriver.exe
C:\WINDOWS\system32
`-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97f4ffe5f8faf2f3e5fee1f2e5d7a5b9a4a4b9a5" rel="noreferrer noopener nofollow">[email protected]</a>
  +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4d0d1d8f4879a849a84" rel="noreferrer noopener nofollow">[email protected]</a>
  | +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="27404b4845455e671109160917" rel="noreferrer noopener nofollow">[email protected]</a>
  | | `-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="106079766950223e233e20" rel="noreferrer noopener nofollow">[email protected]</a>
  | +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4d489c9c5d4e4958a968a94" rel="noreferrer noopener nofollow">[email protected]</a>
  | `-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="12627b746b52213c223c22" rel="noreferrer noopener nofollow">[email protected]</a>
  +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa9f828e889b998ed780938abacbd4ccd4cc" rel="noreferrer noopener nofollow">[email protected]</a>
  | +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6a5a9a8a5a7b2ebb5b2b4a3a7ab86f7e8f0e8f6" rel="noreferrer noopener nofollow">[email protected]</a>
  | | +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="661403070207040a034b15121403070b265448554855" rel="noreferrer noopener nofollow">[email protected]</a>
  | | | +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e071d0f1c1c0f172e5f405e405e" rel="noreferrer noopener nofollow">[email protected]</a>
  | | | +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6414160b07011717490a011c100d070f490516031724554a544a53" rel="noreferrer noopener nofollow">[email protected]</a>
  | | | +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0d3d4d2c9cec7ffc4c5c3cfc4c5d2e0918e908e93" rel="noreferrer noopener nofollow">[email protected]</a>
  | | | `-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4d1d0cdc889c0c1d4d6c1c7c5d0c1e4958a948a96" rel="noreferrer noopener nofollow">[email protected]</a>
  | | `-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="52262b223736332020332b12627c627c64" rel="noreferrer noopener nofollow">[email protected]</a>
  | +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="01656463746641332f372f38" rel="noreferrer noopener nofollow">[email protected]</a>
  | | `-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dab7a99ae8f4eaf4ea" rel="noreferrer noopener nofollow">[email protected]</a>
  | +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f29f99969b8082b2c2dcc7dcc2" rel="noreferrer noopener nofollow">[email protected]</a>
  | `-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0d9c1d5dacce0928e948e91" rel="noreferrer noopener nofollow">[email protected]</a>
  |   `-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1573713866797c76706755243b253b24" rel="noreferrer noopener nofollow">[email protected]</a>
  |     `-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7a7b2b9b397e6f9e5f9e7" rel="noreferrer noopener nofollow">[email protected]</a>
  +-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="deb5bba99eeef0e9f0ee" rel="noreferrer noopener nofollow">[email protected]</a>
  `-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6e03050a071c1e2e5e405b405f" rel="noreferrer noopener nofollow">[email protected]</a>
    `-- <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e6367606763677d7a4e3e203e2036" rel="noreferrer noopener nofollow">[email protected]</a>

npm WARN enoent ENOENT: no such file or directory, open 'C:\WINDOWS\system32\package.json'
npm WARN system32 No description
npm WARN system32 No repository field.
npm WARN system32 No README data
npm WARN system32 No license field.

C:\WINDOWS\system32>npm update chromedriver

C:\WINDOWS\system32>chromedriver -version
ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9)

C:\WINDOWS\system32>

我做错了什么/遗漏了什么?

最佳答案

很可能您的路径中有另一个 chromedriver。您可以在cmd提示符下使用PATH命令来检查路径中是否有另一个chromedriver。如果您有另一个 chromedriver,您可以通过下载所需版本来手动更新它,也可以将 npm 安装的版本添加到您的 PATH(位于以下位置):

C:\WINDOWS\system32\node_modules\chromedriver\lib\chromedriver

此外,您可以在上述位置检查 chromedriver 的版本

C:\WINDOWS\system32>C:\WINDOWS\system32\node_modules\chromedriver\lib\chromedriver --version

关于selenium-webdriver - 如何使用 NPM 更新适用于 Windows 的 ChromeDriver?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47602388/

相关文章:

selenium - 使用 Protractor 方便记录

selenium - 如何在日志中打印作为 TestNG 中一组的一部分运行的测试数?

javascript - 部署 Azure 应用服务时无法安装 Node 模块

javascript - Webpack 不注入(inject)变量

java - 有没有办法在我的测试自动化套件目录中自动更新 chromedriver?

javascript - Selenium::WebDriver::Error::ElementNotVisibleError:使用 Chrome 浏览器时调用 send_key 函数时元素不可见

javascript - 无法使用 Selenium 单击按钮

node.js - 我想在 npm 中创建一个文件,但不想追加该文件(如果它已经存在)

c# - Selenium/Chrome - 选择没有 ID 的复选框输入

javascript - 无法使用 Protractor 虚拟重复选择元素