Sync implementation of the WebDriver protocol in Node.js.
Keep up to date with changes by checking the releases.
On Ubuntu, you need to make sure you have libcurl installed.
sudo apt-get install libcurl4-openssl-dev
npm install webdriver-http-sync
Invocation:
var driver = new WebDriver(serverUrl, desiredCapabilities, httpOptions);
Simple Example:
var WebDriver = require('webdriver-http-sync');
var desiredCapabilities = {browserName: 'firefox'};
// Assuming selenium (packaged separately) has already been started:
// java -jar selenium-server-standalone-2.42.2.jar
var driver = new WebDriver('http://127.0.0.1:4444/wd/hub', desiredCapabilities);
driver.navigateTo('http://www.google.com');
Method | Description |
---|---|
driver.navigateTo(url) |
Navigates the browser to the specificed relative or absolute url. If relative, the root is assumed to be http://127.0.0.1:#{applicationPort} , where applicationPort is passed in to the options for testium.runTests . |
driver.refresh() |
Refreshes the browser. |
driver.getElement(cssSelector) |
Finds an element on the page using the cssSelector and returns an Element. |
driver.getElements(cssSelector) |
Finds all elements on the page using the cssSelector and returns an array of Elements. |
driver.setElementTimeout(milliseconds) |
Sets a timeout for WebDriver to find elements with getElement and getElements . |
driver.getUrl() |
Returns the current url of the page. |
driver.getPageTitle() |
Returns the current page title. |
driver.getPageSource() |
Returns the current page's html source. |
driver.getScreenshot() |
Returns screenshot as a base64 encoded PNG. |
driver.evaluate(javascriptString) |
Executes the given javascript. It must contain a return statement in order to get a value back. |
driver.setCookie(Cookie) |
Sets a cookie on the current page's domain. Cookie = { name, value, path='/' } |
driver.getCookies() |
Returns all cookies visible to the current page. |
driver.clearCookies() |
Deletes all cookies visible to the current page. |
driver.setLocalStorageKey(key, value) |
Sets a local storage item for the current page. |
driver.getLocalStorageKeys() |
Returns all local storage keys visible to the current page. |
driver.clearLocalStorage() |
Deletes all local storage visible to the current page. |
driver.acceptAlert() |
Accepts the visable alert. |
driver.dismissAlert() |
Dismisses the visable alert. |
driver.getAlertText() |
Gets the visable alert's text. |
driver.typeAlert(text) |
Send text to the visable alert's input box. |
driver.getGeolocation() |
Returns the browser's HTML5 geolocation. Ex: {latitude: 37.425, longitude: -122.136, altitude: 10.0} . Not supported in all browsers. |
driver.setGeolocation(location) |
Set the browser's HTML5 geolocation. Expects location to be an object like {latitude: 37.425, longitude: -122.136, altitude: 10.0} . Not supported in all browsers. |
driver.close() |
Closes the WebDriver session. |
element = driver.getElement(selector)
Method | Description |
---|---|
element.get(attribute) |
Returns the element's specified attribute, which can be text , which returns the visible text of that element. |
element.getLocation() |
Return an element's pixel location on the page. Ex: { y: 80, x: 406 } |
element.getLocationInView() |
Return an element's pixel location on the screen once it has been scrolled into view. Ex: { y: 80, x: 406 } |
element.getSize() |
Returns an element's size in pixels. Ex: { height: 207, width: 269 } |
element.isVisible() |
Returns true if the element is visible. |
element.type(strings...) |
Sends strings... to the input element. |
element.clear() |
Clears the input element. |
element.click() |
Calls click on the element. |
There are 97 WebDriver methods! The progress of implementing all of them is visualized below.
The most important and often used methods are already implemented. You can help out by implementing more methods.