0
votes

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.

1
To the first look I see 2 problems here, review_balance does not return anything not even a Promise.norbitrial
And what would be the second problem norbitrial?Prince_Matthew
1. You should return a value because the function gives you back undefined which is not good for await, 2. The return type should be Promise. Read further here: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…norbitrial
The function does not return any value, it just prints something in the console...Prince_Matthew
In that case just remove the async and await keywords because they are not used.norbitrial

1 Answers

0
votes

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);