Getting error in selenium with node.js automation



  • I am working on automation. I am using Selenium with nodejs code. I am just beginning to learn selenium with nodejs. I am trying to open a application, but I am getting error.

    Here is my sample code... I am working on ubuntu os.

    I have installed nodejs, selenium-webdriver, and chromedriver

    var webdriver= require('selenium-webdriver'),
       By= require('selenium-webdriver').By,
       until= require('selenium-webdriver').until;
    
    var driver = new webdriver.Builder()
        .forBrowser('chrome')
        .build();
    
    
    driver.get('http://demo.mahara.org');
    driver.findElement(By.id('login_login_username')).sendKeys('student1');
    driver.findElement(By.id('login_login_password')).sendKeys('Testing1');
    driver.findElement(By.id('login_submit')).click();
    
    
    driver.findElement(By.linkText('Settings')).then(function(element) {
        console.log('Yes, found the element');
    }, function(error) {
    console.log('The element was not found, as expected');
    });
    
    
    driver.quit();
    

    Command prompt:

     naveen@naveen-Inspiron-3542:~/Downloads/node-course/first-app$ node login_test.js 
    (node:24642) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
    
    /home/naveen/node_modules/selenium-webdriver/lib/webdriver/promise.js:1761
          throw error;
          ^
    UnknownError: unknown error: unrecognized Blink revision: 49d525d4dafb21903d1cd21025174928a3fdde75
      (Driver info: chromedriver=2.10.267518,platform=Linux 4.4.0-128-generic x86_64)
        at new bot.Error (/home/naveen/node_modules/selenium-webdriver/lib/atoms/error.js:113:18)
        at Object.bot.response.checkResponse (/home/naveen/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
        at /home/naveen/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:152:24
        at /home/naveen/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
        at webdriver.promise.ControlFlow.runInNewFrame_ (/home/naveen/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20)
        at notify (/home/naveen/node_modules/selenium-webdriver/lib/webdriver/promise.js:465:12)
        at notifyAll (/home/naveen/node_modules/selenium-webdriver/lib/webdriver/promise.js:442:7)
        at resolve (/home/naveen/node_modules/selenium-webdriver/lib/webdriver/promise.js:420:7)
        at fulfill (/home/naveen/node_modules/selenium-webdriver/lib/webdriver/promise.js:535:5)
        at /home/naveen/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
    ==== async task ====
    WebDriver.createSession()
        at Function.webdriver.WebDriver.acquireSession_ (/home/naveen/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:149:22)
        at Function.webdriver.WebDriver.createSession (/home/naveen/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:123:30)
        at new Driver (/home/naveen/node_modules/selenium-webdriver/chrome.js:477:36)
        at Builder.build (/home/naveen/node_modules/selenium-webdriver/builder.js:303:14)
        at Object.<anonymous> (/home/naveen/Downloads/node-course/first-app/login_test.js:7:6)
        at Module._compile (module.js:571:32)
        at Object.Module._extensions..js (module.js:580:10)
        at Module.load (module.js:488:32)
        at tryModuleLoad (module.js:447:12)
    

    When I execute like this... It is working fine...

    naveen@naveen-Inspiron-3542:~$ node
    > var webdriver=require('selenium-webdriver');
    undefined
    > var driver=new webdriver.Builder().forBrowser('chrome').build();
    undefined
    > (node:4574) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
    


  • i don't know how above code is working, as there is two important things are missing.

    1. your chromedriver is outdated and you should add chromedriver path to driver build.

    2. each and every driver command executed as a promise so you need to handle them or use async await to wait for them.

    below code is working for me it it can help:

    const webdriver= require('selenium-webdriver'),
    chrome = require('selenium-webdriver/chrome');
    
    (async function(){
        let o = new chrome.Options();
    o.setChromeBinaryPath('chrome-binary-path');
    
    var driver = new webdriver.Builder()
        .setChromeOptions(o)
        .forBrowser('chrome')
        .build();
    
    await driver.get('http://demo.mahara.org');
    driver.quit();
    })()
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2