Node Selenium ChromeDriver Ubuntu NoSuchSessionError:此驱动程序实例没有有效的会话ID

时间:2016-09-01 12:35:53

标签: node.js selenium ubuntu selenium-webdriver selenium-chromedriver

嘿我正在尝试在

上启动Selenium实例
  • OS:Ubuntu 16.04 64bit / Linux 4.4.0-36-generic
  • 节点:v6.5.0
  • NPM:3.10.3
  • “chromedriver”:“^ 2.23.1”,
  • “selenium-webdriver”:“^ 3.0.0-beta-2”,

我一直收到这个错误。

/var/www/node-bin/portlight-orders/node_modules/selenium-webdriver/lib/webdriver.js:432
        throw new error.NoSuchSessionError(
        ^

NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
    at WebDriverError (/var/www/node-bin/portlight-orders/node_modules/selenium-webdriver/lib/error.js:27:5)
    at NoSuchSessionError (/var/www/node-bin/portlight-orders/node_modules/selenium-webdriver/lib/error.js:122:5)
    at checkHasNotQuit (/var/www/node-bin/portlight-orders/node_modules/selenium-webdriver/lib/webdriver.js:432:15)
    at Driver.schedule (/var/www/node-bin/portlight-orders/node_modules/selenium-webdriver/lib/webdriver.js:393:5)
    at Driver.quit (/var/www/node-bin/portlight-orders/node_modules/selenium-webdriver/lib/webdriver.js:480:23)
    at exitHandler (/var/www/node-bin/portlight-orders/api/services/Selenium.js:12:9)
    at emitOne (events.js:96:13)
    at process.emit (events.js:188:7)
    at process._fatalException (bootstrap_node.js:296:26)

瞥了一眼我发现chromedriver正在运行 http://image.prntscr.com/image/dfc336afbf6f46d59017b4135e9547c3.png enter image description here

var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver = new webdriver.Builder()
    .forBrowser('chrome')
    .build();

module.exports = driver;

function exitHandler(options, err) {
    driver.quit()
}

//do something when app is closing
process.on('exit', exitHandler.bind(null,{cleanup:true}));

//catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {exit:true}));

//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));

1 个答案:

答案 0 :(得分:0)

在使用任何驱动程序实例之前,请检查该驱动程序会话是否处于活动状态,我们有两种情况 1.会话ID存在  如果会话ID存在,那么我们可以更进一步 2.会话ID不存在 所以我们不能再进一步停止