2.7.1 • Published 6 years ago

webdriver-http-sync v2.7.1

Weekly downloads
58
License
BSD-3-Clause
Repository
github
Last release
6 years ago

webdriver-http-sync

Sync implementation of the WebDriver protocol in Node.js.

Keep up to date with changes by checking the releases.

Tested on node.js 0.10.* and io.js.

Install

On Ubuntu, you need to make sure you have libcurl installed. sudo apt-get install libcurl4-openssl-dev

npm install webdriver-http-sync

WebDriver API

WebDriver

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');

Sauce Labs

You can use this library with SauceLabs or any another browser service with authorization. Just add your credentials into URL:

var WebDriver = require('webdriver-http-sync');
var desiredCapabilities = {browserName: 'firefox'};

var driver = new WebDriver('http://SAUCE_USERNAME:SAUCE_API_KEY@ondemand.saucelabs.com:4444/wd/hub', desiredCapabilities);
driver.navigateTo('http://www.google.com');
MethodDescription
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.setTimeouts(type, milliseconds)Sets a timeout for a certain type of operation. Valid types are: "script" for script timeouts, "implicit" for modifying the implicit wait timeout and "page load" for setting a page load timeout.
driver.setElementTimeout(milliseconds)Sets a timeout for WebDriver to find elements with getElement and getElements.
driver.setScriptTimeout(milliseconds)Sets a timeout for WebDriver to execute async scripts with evaluateAsync.
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.getCapabilities()Returns browser capabilities for current session.
driver.evaluate(javascriptString)Executes the given javascript. It must contain a return statement in order to get a value back.
driver.evaluateAsync(javascriptString)Executes the given asynchronous javascript. The executed script must signal that is done by invoking the provided callback, which is always provided as the final argument to the function.
driver.setCookie(Cookie)Sets a cookie on the current page's domain. Cookie = { name, value, path='/' }
driver.switchToDefaultFrame()Change focus to default content on the page.
driver.switchToFrame(indexOrNameOrId)Change focus to another frame on the page.
driver.getWindowHandles()Retrieve the list of all window handles available to the session.
driver.getCurrentWindowHandle()Retrieve the current window handle.
driver.switchToWindow(name)Change focus to another window. The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute.
driver.closeWindow()Close the current window.
driver.getWindowSize(windowHandle)Get the size of the specified window. If no windowHandle in specified the current window is assumed. Returns an object with width and height values.
driver.setWindowSize(width, height, windowHandle)Change the size of the specified window. If no windowHandle in specified the current window is assumed.
driver.getWindowPosition(windowHandle)Get the position of the specified window. If no windowHandle in specified the current window is assumed. Returns an object with x and y values.
driver.setWindowPosition(x, y, windowHandle)Change the position of the specified window. If no windowHandle in specified the current window is assumed.
driver.maximizeWindow(windowHandle)Maximize the specified window if not already maximized. If no windowHandle in specified the current window is assumed.
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.getConsoleLogs()Get browser console logs.
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.buttonDown(button)Presses down the pointer button (default 0 = left, can be 1 = middle, 2 = right) at location of last element.movePointerRelativeTo()
driver.buttonUp(button)Like driver.buttonDown()
driver.click(button)Like driver.buttonDown()
driver.sendKeys(strings...)Sends strings... to the active element.
driver.close()Closes the WebDriver session.

Element

element = driver.getElement(selector)

MethodDescription
element.get(attribute)Returns the element's specified attribute, which can be text, which returns the visible text of that element.
element.getElement(cssSelector)Finds a child element of element using the cssSelector and returns an Element.
element.getElements(cssSelector)Finds all child elements of the element using the cssSelector and returns an array of Elements.
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.
element.movePointerRelativeTo(xOffset, yOffset)Moves the pointer to the coordinates given, relative to this element (default centered)

Contributing

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.

StatusHTTP MethodPathSummary
not-yetGET/statusQuery the server's current status.
implPOST/sessionCreate a new session.
not-yetGET/sessionsReturns a list of the currently active sessions.
implGET/session/:sessionIdRetrieve the capabilities of the specified session.
implDELETE/session/:sessionIdDelete the session.
implPOST/session/:sessionId/timeoutsConfigure the amount of time that a particular type of operation can execute for before they are aborted and a Timeout error is returned to the client.
implPOST/session/:sessionId/timeouts/async_scriptSet the amount of time, in milliseconds, that asynchronous scripts executed by /session/:sessionId/execute_async are permitted to run before they are aborted and a Timeout error is returned to the client.
implPOST/session/:sessionId/timeouts/implicit_waitSet the amount of time the driver should wait when searching for elements.
implGET/session/:sessionId/window_handleRetrieve the current window handle.
implGET/session/:sessionId/window_handlesRetrieve the list of all window handles available to the session.
implGET/session/:sessionId/urlRetrieve the URL of the current page.
implPOST/session/:sessionId/urlNavigate to a new URL.
not-yetPOST/session/:sessionId/forwardNavigate forwards in the browser history, if possible.
not-yetPOST/session/:sessionId/backNavigate backwards in the browser history, if possible.
not-yetPOST/session/:sessionId/refreshRefresh the current page.
implPOST/session/:sessionId/executeInject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
implPOST/session/:sessionId/execute_asyncInject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
implGET/session/:sessionId/screenshotTake a screenshot of the current page.
not-yetGET/session/:sessionId/ime/available_enginesList all available engines on the machine.
not-yetGET/session/:sessionId/ime/active_engineGet the name of the active IME engine.
not-yetGET/session/:sessionId/ime/activatedIndicates whether IME input is active at the moment (not if it's available.
not-yetPOST/session/:sessionId/ime/deactivateDe-activates the currently-active IME engine.
not-yetPOST/session/:sessionId/ime/activateMake an engines that is available (appears on the listreturned by getAvailableEngines) active.
implPOST/session/:sessionId/frameChange focus to another frame on the page.
implPOST/session/:sessionId/windowChange focus to another window.
implDELETE/session/:sessionId/windowClose the current window.
implPOST/session/:sessionId/window/:windowHandle/sizeChange the size of the specified window.
implGET/session/:sessionId/window/:windowHandle/sizeGet the size of the specified window.
implPOST/session/:sessionId/window/:windowHandle/positionChange the position of the specified window.
implGET/session/:sessionId/window/:windowHandle/positionGet the position of the specified window.
implPOST/session/:sessionId/window/:windowHandle/maximizeMaximize the specified window if not already maximized.
implGET/session/:sessionId/cookieRetrieve all cookies visible to the current page.
implPOST/session/:sessionId/cookieSet a cookie.
implDELETE/session/:sessionId/cookieDelete all cookies visible to the current page.
not-yetDELETE/session/:sessionId/cookie/:nameDelete the cookie with the given name.
implGET/session/:sessionId/sourceGet the current page source.
implGET/session/:sessionId/titleGet the current page title.
Partially ImplementedPOST/session/:sessionId/elementSearch for an element on the page with a CSS selector, starting from the document root.
Partially ImplementedPOST/session/:sessionId/elementsSearch for multiple elements on the page with a CSS selector, starting from the document root.
not-yetPOST/session/:sessionId/element/activeGet the element on the page that currently has focus.
not-yetGET/session/:sessionId/element/:idDescribe the identified element.
Partially ImplementedPOST/session/:sessionId/element/:id/elementSearch for an element on the page, starting from the identified element.
Partially ImplementedPOST/session/:sessionId/element/:id/elementsSearch for multiple elements on the page, starting from the identified element.
implPOST/session/:sessionId/element/:id/clickClick on an element.
not-yetPOST/session/:sessionId/element/:id/submitSubmit a FORM element.
implGET/session/:sessionId/element/:id/textReturns the visible text for the element.
Partially ImplementedPOST/session/:sessionId/element/:id/valueSend a sequence of key strokes to an element.
implPOST/session/:sessionId/keysSend a sequence of key strokes to the active element.
not-yetGET/session/:sessionId/element/:id/nameQuery for an element's tag name.
implPOST/session/:sessionId/element/:id/clearClear a TEXTAREA or text INPUT element's value.
not-yetGET/session/:sessionId/element/:id/selectedDetermine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected.
not-yetGET/session/:sessionId/element/:id/enabledDetermine if an element is currently enabled.
implGET/session/:sessionId/element/:id/attribute/:nameGet the value of an element's attribute.
not-yetGET/session/:sessionId/element/:id/equals/:otherTest if two element IDs refer to the same DOM element.
implGET/session/:sessionId/element/:id/displayedDetermine if an element is currently displayed.
implGET/session/:sessionId/element/:id/locationDetermine an element's location on the page.
implGET/session/:sessionId/element/:id/location_in_viewDetermine an element's location on the screen once it has been scrolled into view.
implGET/session/:sessionId/element/:id/sizeDetermine an element's size in pixels.
not-yetGET/session/:sessionId/element/:id/css/:propertyNameQuery the value of an element's computed CSS property.
not-yetGET/session/:sessionId/orientationGet the current browser orientation.
not-yetPOST/session/:sessionId/orientationSet the browser orientation.
implGET/session/:sessionId/alert_textGets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog.
implPOST/session/:sessionId/alert_textSends keystrokes to a JavaScript prompt() dialog.
implPOST/session/:sessionId/accept_alertAccepts the currently displayed alert dialog.
implPOST/session/:sessionId/dismiss_alertDismisses the currently displayed alert dialog.
implPOST/session/:sessionId/movetoMove the pointer by an offset of the specified element.
implPOST/session/:sessionId/clickClick any pointer button (at the coordinates set by the last moveto command).
implPOST/session/:sessionId/buttondownClick and hold the left pointer button (at the coordinates set by the last moveto command).
implPOST/session/:sessionId/buttonupReleases the pointer button previously held (where the pointer is currently at).
not-yetPOST/session/:sessionId/doubleclickDouble-clicks at the current pointer coordinates (set by moveto).
not-yetPOST/session/:sessionId/touch/clickSingle tap on the touch enabled device.
not-yetPOST/session/:sessionId/touch/downFinger down on the screen.
not-yetPOST/session/:sessionId/touch/upFinger up on the screen.
not-yetPOSTsession/:sessionId/touch/moveFinger move on the screen.
not-yetPOSTsession/:sessionId/touch/scrollScroll on the touch screen using finger based motion events.
not-yetPOSTsession/:sessionId/touch/scrollScroll on the touch screen using finger based motion events.
not-yetPOSTsession/:sessionId/touch/doubleclickDouble tap on the touch screen using finger motion events.
not-yetPOSTsession/:sessionId/touch/longclickLong press on the touch screen using finger motion events.
not-yetPOSTsession/:sessionId/touch/flickFlick on the touch screen using finger motion events.
not-yetPOSTsession/:sessionId/touch/flickFlick on the touch screen using finger motion events.
implGET/session/:sessionId/locationGet the current geo location.
implPOST/session/:sessionId/locationSet the current geo location.
implGET/session/:sessionId/local_storageGet all keys of the storage.
implPOST/session/:sessionId/local_storageSet the storage item for the given key.
implDELETE/session/:sessionId/local_storageClear the storage.
not-yetGET/session/:sessionId/local_storage/key/:keyGet the storage item for the given key.
not-yetDELETE/session/:sessionId/local_storage/key/:keyRemove the storage item for the given key.
not-yetGET/session/:sessionId/local_storage/sizeGet the number of items in the storage.
not-yetGET/session/:sessionId/session_storageGet all keys of the storage.
not-yetPOST/session/:sessionId/session_storageSet the storage item for the given key.
not-yetDELETE/session/:sessionId/session_storageClear the storage.
not-yetGET/session/:sessionId/session_storage/key/:keyGet the storage item for the given key.
not-yetDELETE/session/:sessionId/session_storage/key/:keyRemove the storage item for the given key.
not-yetGET/session/:sessionId/session_storage/sizeGet the number of items in the storage.
implPOST/session/:sessionId/logGet the log for a given log type.
not-yetGET/session/:sessionId/log/typesGet available log types.
not-yetGET/session/:sessionId/application_cache/statusGet the status of the html5 application cache.
2.7.1

6 years ago

2.7.0

7 years ago

2.6.0

7 years ago

2.5.0

8 years ago

2.4.1

8 years ago

2.4.0

8 years ago

2.3.0

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.12.0

9 years ago

0.11.0

10 years ago

0.10.0

10 years ago

0.9.0

10 years ago

0.8.0

10 years ago

0.7.1

10 years ago

0.7.0

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago