我正在尝试构建一些代码,但是出现了两个错误:
(节点:12909)UnhandledPromiseRejectionWarning:NoSuchSessionError:试图在不建立连接的情况下运行命令 在Object.throwDecodedError(/home/matthew/node_modules/selenium-webdriver/lib/error.js:550:15) 在parseHttpResponse(/home/matthew/node_modules/selenium-webdriver/lib/http.js:563:13) 在Executor.execute(/home/matthew/node_modules/selenium-webdriver/lib/http.js:489:26) 在 在process._tickCallback(内部/进程/next_tick.js:188:7) (节点:12909)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。该错误是由于在没有catch块的情况下抛出异步函数而引起的,或者是由于拒绝了未经.catch()处理的诺言而引起的。 (拒绝ID:1) (节点:12909)[DEP0018] DeprecationWarning:已弃用未处理的承诺拒绝。将来,未处理的承诺拒绝将以非零退出代码终止Node.js进程。 (节点:12909)UnhandledPromiseRejectionWarning:NoSuchSessionError:试图在不建立连接的情况下运行命令 在Object.throwDecodedError(/home/matthew/node_modules/selenium-webdriver/lib/error.js:550:15) 在parseHttpResponse(/home/matthew/node_modules/selenium-webdriver/lib/http.js:563:13) 在Executor.execute(/home/matthew/node_modules/selenium-webdriver/lib/http.js:489:26) 在 在process._tickCallback(内部/进程/next_tick.js:188:7) (节点:12909)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。该错误是由于在没有catch块的情况下抛出异步函数而引起的,或者是由于拒绝了未经.catch()处理的诺言而引起的。 (拒绝ID:2)
function review_balance() {
if (balance_amount > 0) {
console.log("This address has " + balance_amount + "Bitcoin");
}
else {
console.log("0 Bitcoins!");
}
}
async function searching() {
console.log("Waiting for address to be scanned on the Bitcoin blockchain...");
const result = await review_balance();
console.log(result);
}
searching();
driver.close();
这是程序中最重要的部分,包含问题。谁能给我任何建议?我真的很感激。
答案 0 :(得分:0)
使用Promise解决方案:
let check_balance = new Promise((resolve, reject) => {
driver.get("https://explorer.bitcoin.com/btc/address/" + address);
let balance_amount = driver.findElement(webdriver.By.className("amount")).getText();
if (balance_amount > 0) {
resolve('This wallet has ' + balance_amount + ' Bitcoins.');
}
else {
reject('0 Bitcoins!');
}})check_balance.then((message) => {
console.log(message);}).catch((message) => {
console.log(message);}) setTimeout(function () {
driver.quit();}, 8000);