Так что я недавно начал изучать селен с Node JS. Я тестировал пример кода, приведенный на веб-сайте Mozilla . Я смог исправить все остальное, но когда эта конкретная строка
driver.quit();
вызывает это исключение:
(node:3370) UnhandledPromiseRejectionWarning: NoSuchSessionError: Tried to run command without establishing a connection
at Object.throwDecodedError (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/http.js:468:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7
(node:3370) 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: 2)
(node:3370) [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:3370) UnhandledPromiseRejectionWarning: NoSuchSessionError: Tried to run command without establishing a connection
at Object.throwDecodedError (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/http.js:468:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7
(node:3370) 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: 3)
(node:3370) UnhandledPromiseRejectionWarning: NoSuchSessionError: Tried to run command without establishing a connection
at Object.throwDecodedError (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/http.js:468:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7
(node:3370) 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: 4)
(node:3370) UnhandledPromiseRejectionWarning: NoSuchSessionError: Tried to run command without establishing a connection
at Object.throwDecodedError (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/media/slim/Work/Online_Advertising/Selenium/node_modules/selenium-webdriver/lib/http.js:468:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7
(node:3370) 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: 5)
Исключение не появляется, если я удаляю driver.quit ().
Кроме того, driver.getTitle () возвращает пустое значение. Мой код выглядит следующим образом:
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com');
var searchBar = driver.wait(
until.elementLocated(By.name('q'),5000)
);
searchBar.sendKeys('webdriver');
driver.findElement({name:'q'}).sendKeys(webdriver.Key.ENTER);
driver.wait(
until.titleContains("webdriver")
).then(
driver.getTitle().then(function(title) {
console.log(title);
})
);
console.log печатает пустую строку в терминале.
Постскриптум Я работаю в среде Linux