2
votes

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!

1
Instead of http try https in driver.get() please, and let me know. - Sarthak Srivastava
please format your code correctly - Benjamin
@SarthakSrivastava, even with https instead of http it returns the same error.. The Chrome browser pops up, but nothing's executed. - Haitham Hirt

1 Answers

0
votes

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

Are you able to access the localhost url manually?