简体   繁体   中英

NodeJS Selenium Chrome Webdriver Connection Refused

I'm new to NodeJS and Selenium Webdriver and I wanted to launch a simple test code:

 var webdriver = require("selenium-webdriver"); function createDriver() { var driver = new webdriver.Builder() .usingServer('http://localhost:4444/wd/hub') .withCapabilities(webdriver.Capabilities.chrome()) .build(); driver.manage().timeouts().setScriptTimeout(10000); return driver; } var driver = createDriver(); driver.get("http://www.google.com"); driver.getTitle().then(function (title) { console.log(title); }); driver.quit(); 

I have everything setup, the chrome driver and the server launched.

But I'm getting this error:

(node:3080) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): WebDriverError: java.net.ConnectException: Connection refused: connect (node:3080) [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:3080) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): WebDriverError: java.net.ConnectException: Connection refused: connect (node:3080) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): WebDriverError: java.net.ConnectException: Connection refused: connect

Can you guys please help? Thanks!

Have you installed all the relevant modules including chromedriver using npm i --save-dev?

Are you able to access the localhost url manually?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM