今後の自動化プロジェクトでは、Selenium for Firefoxを利用したいと思います。 このガイド に従いました。 「node /path/to/script/scriptName.js」を使用して、そのガイド内から言及されたスクリプトを実行したい場合、Firefoxウィンドウが1秒間ポップアップしてすぐに閉じます。これまでのスクリプトは、ガイドの内容をコピー/貼り付けするだけです。
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)
古いバージョンのSelenium-webdriver この脅威 をインストールするという形で回避策を見つけました。
npm i [email protected]