1

When the code below is executed it opens chrome and the search bar is filled already with this data;,. I haven't mentioned it anywhere in the code still this happens. Moreover, there are few errors that appear each time I try to run the code.

var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver =new webdriver.Builder()
    .forBrowser('chrome')
    .build();

driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('wiki');
driver.findElement(By.name('btnG')).click();
driver.wait(check_title,1000);

function check_title(){
  var promise = driver.getTitle().then((title)=>{
    if(title === 'wiki - Google Search'){
      console.log('success!');
      return true;
    }else{
      console.log("failed!!");
    }
  });
  return promise;
}

I get this error

 (node:15384) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61227
    (node:15384) [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:15384) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61227
    (node:15384) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61227
    (node:15384) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61227
    (node:15384) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:61227

How can this be removed?

Raj Chandra
  • 13
  • 1
  • 5

1 Answers1

0

Use .clear(); to clear the input field for the search bar before you send keys to it. For details on what it does see the answer to this question.

The Promise is not handling the reject with a catch. Following the answers from another question on promise rejection.

var promise = driver.getTitle().then((title)=>{
    if(title === 'wiki - Google Search') {
      console.log('success!');
      return true;
    } else {
      console.log("failed!!");
    }
  }).catch(function () {
      console.log("Promise Rejected!");
  });
lloyd
  • 1,683
  • 2
  • 19
  • 23