0
votes

i have installed the npm selenium-driver and now i want try to use it.

i have created a js file test.js

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

var driver = new webdriver.Builder()
  .usingServer("http://docker01.localhost:4444/wd/hub")
  .forBrowser('firefox')
  .build();

driver.get('http://demo.mahara.org');
driver.findElement(By.id('login_login_username')).then(function(links){
console.log('Found', links.length, 'Wiki links.' )
driver.quit();
});

from my console i send this node cmd

$ node tests\js\test.js

(node:5648) UnhandledPromiseRejectionWarning: NoSuchElementError: Unable to locate element: *[id="login_login_username"]
at Object.throwDecodedError (C:\xampp\htdocs\next-noregressiontests\src\test\javascript\node_modules\selenium-webdriver\lib\error.js:550:15)
at parseHttpResponse (C:\xampp\htdocs\next-noregressiontests\src\test\javascript\node_modules\selenium-webdriver\lib\http.js:542:13)
at Executor.execute (C:\xampp\htdocs\next-noregressiontests\src\test\javascript\node_modules\selenium-webdriver\lib\http.js:468:26)
at
at process._tickCallback (internal/process/next_tick.js:182:7) (node:5648) 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:5648) [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.

i can not understand where is the problem

2
Make sure that the id value is 'login_login_username'. The error says that there is no such a element exist.Sometime the browser will take time to load the DOM, in such cases also this error will occur.Try some wait before click that element. - Sudha Velan
Could You please provide part of html to check out this element path. - Kovacic

2 Answers

0
votes

This element

[id="login_login_username"]

try this:

[@id="login_login_username"]
0
votes

You need to wait for the element to appear after loading the page. So after driver.get(...), add this:

driver.wait(until.elementLocated(by.id('login_login_username')), 10000, 'Cannot find element');

This will keep looking for the element, and times out after 10s if it doesn't find it.