для предстоящего проекта автоматизации я хочу использовать Селен для Firefox. Я следовал ЭТОМУ РУКОВОДСТВУ. Теперь, когда я хочу запустить упомянутый скрипт из того руководства, использующего 'узел/path/to/script/scriptName.js, окно Firefox открывается для миллисекунды и завершений сразу. Сценарий до сих пор является только скопировать/вставить содержанием от руководства.
Node/npm и webdriver установлены успешно. geckodriver является в '/home' каталогом и помещенный в '$PATH'.
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');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.sleep(1000).then(function() {
driver.findElement(By.name('q')).sendKeys(webdriver.Key.TAB);
});
driver.findElement(By.name('btnK')).click();
driver.sleep(2000).then(function() {
driver.getTitle().then(function(title) {
if(title === 'webdriver - Google Search') {
console.log('Test passed');
} else {
console.log('Test failed');
}
});
});
driver.quit();
Консоль бросает много ошибок затем, но я не могу считать, что точно неправильно функционирует здесь. Кто-либо может сказать мне, что я, возможно, пропустил?
node ~/projects/googleTest.js
(node:21344) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/ruphus/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/ruphus/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/ruphus/node_modules/selenium-webdriver/lib/http.js:468:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:21344) 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:21344) [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:21344) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/ruphus/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/ruphus/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/ruphus/node_modules/selenium-webdriver/lib/http.js:468:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:21344) 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:21344) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/ruphus/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/ruphus/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/ruphus/node_modules/selenium-webdriver/lib/http.js:468:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:21344) 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:21344) UnhandledPromiseRejectionWarning: NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
at promise.finally (/home/ruphus/node_modules/selenium-webdriver/lib/webdriver.js:726:38)
at Object.thenFinally [as finally] (/home/ruphus/node_modules/selenium-webdriver/lib/promise.js:124:12)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:21344) 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: 8)
Я нашел обходное решение в форме установки более старой версии селена-webdriver в этой угрозе.
npm i selenium-webdriver@3.6.0