我是 NodeJS 和 Selenium Webdriver 的新手,我想启动一个简单的测试代码:
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();
我已完成所有设置,chrome 驱动程序和服务器已启动。
但我收到此错误:
(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
各位可以帮忙吗?谢谢!
最佳答案
您是否使用 npm i --save-dev 安装了所有相关模块,包括 chromedriver?
您可以手动访问本地主机 URL 吗?
关于javascript - NodeJS Selenium Chrome Webdriver 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48787008/