Reputation: 45
I am trying to build some code but I get those two errors:
(node:12909) UnhandledPromiseRejectionWarning: NoSuchSessionError: Tried to run command without establishing a connection at 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: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:12909) [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:12909) UnhandledPromiseRejectionWarning: NoSuchSessionError: Tried to run command without establishing a connection at 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: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection 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();
This is the part of the program that is the most important and contains the problem. Can anyone give me any advice? I would be really thankful.
Upvotes: 0
Views: 801
Reputation: 45
Solution using 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);
Upvotes: 0