2
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().forBrowser('chrome').build();
driver.get('http://www.google.com');
driver.findElement({name: 'q'}).sendKeys('webdriverjs');
driver.findElement({name: 'q'}).sendKeys(webdriver.Key.ENTER);
driver.manage().window().maximize();
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://127.0.0.1:12148/devtools/browser/86604bd8-c770-4659-bdaf-0abbf4cd790c (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 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.

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
  • 2
    Questions seeking debugging help (**"why isn't this code working?"**) must include the desired behavior, a *specific problem or error and the shortest code necessary* to reproduce it **in the question itself**. Questions without a **clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example.](http://stackoverflow.com/help/mcve) – Neil Lunn Apr 26 '18 at 06:51
  • Please add HTML snippet. – Ishita Shah Apr 26 '18 at 07:36
  • Possible duplicate of [NoSuchElementExeption, selenium unable to locate element](https://stackoverflow.com/questions/48471321/nosuchelementexeption-selenium-unable-to-locate-element) – undetected Selenium Apr 26 '18 at 10:06
  • At `driver.findElement({xpath: '//*[@id="rso"]/div/div/div[1]/div/div/h3/a'}).click();` line? – undetected Selenium Apr 26 '18 at 10:19

0 Answers0