-1

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.
  • 1
    Is your chromedriver a match for your Chrome browser? – João Farias Jun 8 at 15:58
  • @JoãoFarias this is my ChromeDriver 2.10.267518 version and linux chrome browser 60 am using.. – XtremeTester Jun 9 at 11:59
  • I couldn't find on the Google wesite the associated version for Chrome 60, but according to this answer (sqa.stackexchange.com/a/23805/12740) "Chrome 60-62 works with chromedriver 2.33" and "older versions, use chromedriver 2.10". Where have you found the information that 2.10 matches 60? – João Farias Jun 10 at 8:37
0

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();
})()
0

If you see that error: "DeprecationWarning: os.tmpDir() is deprecated", it means you are trying to call async methods without await. It means you are missing await somewhere or you are not using async. FYI, WebDriver's JavaScript API is entirely asynchronous, and every Selenium WebDriver command returns a Promise object. So you need to wait before that command gets executed. If you wanna learn more about that: https://codoid.com/understanding-asynchronous-webdriverjs/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.