Unable to find solution for automation with Nodejs

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Unable to find solution for automation with Nodejs

Shatabdi Pal

I am pretty new to nodejs, can someone help me please? 

This is my code below::

    var webdriver = require('selenium-webdriver');
    var driver = new webdriver.Builder().forBrowser('chrome').build();
    driver.findElement({name: 'q'}).sendKeys('webdriverjs');
    driver.findElement({name: 'q'}).sendKeys(webdriver.Key.ENTER);
    driver.wait(webdriver.until.elementLocated({xpath: '//*[@id="rso"]/div/div/div[1]/div/div/h3/a'}), 30000);
    driver.findElement({xpath: '//*[@id="rso"]/div/div/div[1]/div/div/h3/a'}).click();

Getting the following error:

    DevTools listening on ws://
    (node:15596) UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="rso"]/div/div/div[1]/div/div/h3/a"}
      (Session info: chrome=65.0.3325.181)
      (Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 10.0.16299 x86_64)
        at Object.checkLegacyResponse (C:\Users\SPal\webdriverjs\node_modules\selenium-webdriver\lib\error.js:585:15)
        at parseHttpResponse (C:\Users\SPal\webdriverjs\node_modules\selenium-webdriver\lib\http.js:533:13)
        at Executor.execute (C:\Users\SPal\webdriverjs\node_modules\selenium-webdriver\lib\http.js:468:26)
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:182:7)
    (node:15596) 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:15596) [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.

You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7794d6ce-deba-4241-bdc6-76fbbd8fc7b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.