selenium-extend is an npm module that makes async selenium-webdriver code a lot more sane. It's most valuable when used in conjunction with the selenium chromedriver and makes working with chrome extensions in the context of the chromedriver much easier.
selenium-extend does not overwrite existing driver functionality. selenium-extend adds an extend object with various methods that wrap selenium-webdriver functions into functions that make sense in the context of navigating a browser.
##Installation
npm install selenium-extend
##Initialization
Constructing a fresh driver:
var extend = require('selenium-extend');
// constructing raw chrome
var driverPath = "path/to/chromedriver";
var driver = extend.createChrome(driverPath); //returns a Chrome WebDriver
// constructing chrome with an extension
var extensionPath = "path/to/chrome/extension/folder"; //unpacked chrome extension
var driverPath = "path/to/chromedriver";
var driver = extend.createChromeWithExtension(extensionPath, driverPath);
Applying to an existing driver:
var extend = require('selenium-extend');
extend.addExtend(driver);
You can also set the maximum wait time for async events:
extend.setWaitTime(10000); // sets maximum wait time to 10000ms
// default WAITTIME is 10000ms
##API
Enable incognito for chrome extensions/selenium web driver:
driver.extend.enableIncognito(); // enables for both selenium and extension
driver.extend.enableIncognito(n); // enables for up to n extensions, in order
// from first to last, selenium is always
// the first extension
Check is an element is clickable:
var clickable = driver.extend.isClickable(css); // returns boolean true or false
// waits until WAITTIME
// css is a css selector
Click on an element:
driver.extend.click(css); //css is selector
Check if an element exists:
driver.extend.exists(css);
Get the text value of an element:
driver.extend.getText(css);
Emulate selecting text in DOM with a mouse pointer:
// offset1 and 2 are the character offsets of the text node to highlight text in
driver.extend.selectText(css, offset1, offset2);
Type text into an element:
driver.extend.typeText(css, "text to type in element");
Switch to the next window:
driver.extend.toNextWindow();
##Future
The following are still to be done: --tests --constructors for other browsers --any other types of browser interactions (e.g. hover, scroll, double click, etc)
##License Created by Shri Ganeshram, please attribute in forks. Licensed under the MIT License.