[英]Cannot resolve error unhandled promise rejection and NoSuchSessionError
我正在嘗試構建一些代碼,但我收到了這兩個錯誤:
(node:12909) UnhandledPromiseRejectionWarning: NoSuchSessionError: 試圖在 Object.throwDecodedError (/home/matthew/node_modules/selenium-webdriver/lib/error.js:550:15) at parseHttpResponse (/home/matthew) 上運行命令而不建立連接/node_modules/selenium-webdriver/lib/http.js:563:13) at Executor.execute (/home/matthew/node_modules/selenium-webdriver/lib/http.js:489:26) at at process._tickCallback (internal /process/next_tick.js:188:7) (node:12909) UnhandledPromiseRejectionWarning:未處理的承諾拒絕。 這個錯誤要么是因為在沒有 catch 塊的情況下拋出了異步函數,要么是因為拒絕了一個沒有用 .catch() 處理過的承諾。 (rejection id: 1) (node:12909) [DEP0018] DeprecationWarning:不推薦使用未處理的承諾拒絕。 將來,未處理的承諾拒絕將使用非零退出代碼終止 Node.js 進程。 (node:12909) UnhandledPromiseRejectionWarning: NoSuchSessionError: 試圖在 parseHttpResponse (/home/matthew) 的 Object.throwDecodedError (/home/matthew/node_modules/selenium-webdriver/lib/error.js:550:15) 處運行命令而不建立連接/node_modules/selenium-webdriver/lib/http.js:563:13) at Executor.execute (/home/matthew/node_modules/selenium-webdriver/lib/http.js:489:26) at at process._tickCallback (internal /process/next_tick.js:188:7) (node:12909) UnhandledPromiseRejectionWarning:未處理的承諾拒絕。 這個錯誤要么是因為在沒有 catch 塊的情況下拋出了異步函數,要么是因為拒絕了一個沒有用 .catch() 處理過的承諾。 (拒絕編號: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();
這是程序中最重要且包含問題的部分。 任何人都可以給我任何建議嗎? 我會很感激的。
使用 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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.