2

我有 Ubuntu 服务器 19.04 64 位。我使用以下软件包:

  • nodejs v10.16.0
  • 火狐 68.0.1

我安装selenium-webdriver ^4.0.0-alpha.4在我的 node.js 项目中。

我还安装geckodriver 0.24.0了以下算法:

sudo wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz
tar -xvzf geckodriver-v0.24.0-linux64.tar.gz
chmod +x geckodriver
sudo mv geckodriver /usr/local/bin/

我的项目有 index.js 和以下代码:

const {Builder, By, Key, util} = require("selenium-webdriver");
const firefox = require('selenium-webdriver/firefox');
async function example() {
    let options = await new firefox.Options()
        .headless();
    let driver = await new Builder().forBrowser("firefox").setFirefoxOptions(options).build();
    await driver.get("https://mobile.facebook.com");  
    await driver.close();
}
example();

当我使用命令启动脚本时,sudo node index.js出现以下错误:

(node:1303) UnhandledPromiseRejectionWarning: WebDriverError: invalid argument: can't kill an exited process
    at Object.throwDecodedError (/var/nodejs/sites/test/node_modules/selenium-webdriver/lib/error.js:550:15)
    at parseHttpResponse (/var/nodejs/sites/test/node_modules/selenium-webdriver/lib/http.js:560:13)
    at Executor.execute (/var/nodejs/sites/test/node_modules/selenium-webdriver/lib/http.js:486:26)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:1303) 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(). (rejection id: 1)
(node:1303) [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.

错误:invalid argument: can't kill an exited process,我不知道如何解决这个问题...如果您需要有关我的情况的更多信息,请问我,我会尽力回答。

UPD:我尝试了最新版本的 geckodriver 并查看了我得到的结果:

0.24.0:WebDriverError: invalid argument: can't kill an exited process

0.23.0:WebDriverError: invalid argument: can't kill an exited process

0.22.0:WebDriverError: invalid argument: can't kill an exited process

0.21.0:WebDriverError: Process unexpectedly closed with status 1

0.20.1:WebDriverError: Process unexpectedly closed with status 1

0.20.0:WebDriverError: Process unexpectedly closed with status 1

...

4

2 回答 2

2

您需要更新您的 Firefox 浏览器,这可能是由于 GeckoDriver 和 Firefox 浏览器不匹配而发生的。

如果这也不起作用,请使用以下版本的壁虎驱动程序,尝试使用壁虎驱动程序的第 2 和第 3 个最新更新版本。

不推荐,您仍然可能需要降级浏览器并尝试最新版本或尝试使用壁虎驱动程序的第 2 和第 3 最新更新版本。当二进制文件可用于最新的 firefox 版本时,您应该尝试使用最新版本进行更新

这也是你的 geckodriver 没有退出的可能性之一,所以它仍然在运行,抑制新会话打开,你可以使用下面的文章来杀死你的 geckodriver 进程

https://www.tecmint.com/find-and-kill-running-processes-pid-in-linux/

于 2019-07-26T09:39:45.363 回答
1

所以,经过长时间测试不同版本的 geckodriver 和 farefox 我解决了我的问题!

我只是尝试将 farefox 降级到 v57.0,但我没有尝试使用较新的版本。我偷用 geckodriver 0.24.0。

有关降级的更多信息https://askubuntu.com/questions/661186/how-to-install-previous-firefox-version

于 2019-07-26T10:59:08.290 回答