Skip to content

Instantly share code, notes, and snippets.

Created November 26, 2012 20:27
Show Gist options
  • Save anonymous/4150413 to your computer and use it in GitHub Desktop.
Save anonymous/4150413 to your computer and use it in GitHub Desktop.
WebDriverJS in node
var webdriver = require('./build/javascript/node/webdriver')
var driver = new webdriver.Builder().
withCapabilities({'browserName': 'chrome'}).
build();
driver.findElement({name: 'not-there'});
/*
timers.js:103
if (!process.listeners('uncaughtException').length) throw e;
^
NoSuchElementError: The element could not be found
at new bot.Error (/usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/atoms/error.js:92:18)
at Object.bot.response.checkResponse (/usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/atoms/response.js:106:9)
at /usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/webdriver/webdriver.js:256:20
at /usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/goog/base.js:1112:15
at webdriver.promise.Application.runInNewFrame_ (/usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/webdriver/promise.js:1308:20)
at notify (/usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/webdriver/promise.js:299:24)
at notifyAll (/usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/webdriver/promise.js:274:7)
at resolve (/usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/webdriver/promise.js:369:7)
at /usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/webdriver/promise.js:1177:10
at /usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/goog/base.js:1112:15
==== async task ====
WebDriver.findElement(By.name("not-there"))
at webdriver.WebDriver.schedule (/usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/webdriver/webdriver.js:240:14)
at webdriver.WebDriver.findElement (/usr/local/user/webdriver/trunk2/build/javascript/node/webdriver/lib/webdriver/webdriver.js:685:17)
at Object.<anonymous> (/usr/local/user/webdriver/trunk2/sample.js:14:8)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
*/
var webdriver = require('./build/javascript/node/webdriver')
var driver = new webdriver.Builder().
withCapabilities({'browserName': 'chrome'}).
build();
driver.get('http://www.google.com');
driver.findElement({name: 'q'}).sendKeys('webdriver');
driver.findElement({name: 'btnG'}).click();
driver.sleep(1000); // Cheat for async UI update
driver.getTitle().then(function(title) {
console.log("Title is: " + title);
});
driver.quit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment