GithubHelp home page GithubHelp logo

federicobucchi / selenium-node-webdriver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from waterfallengineering/selenium-node-webdriver

0.0 2.0 0.0 293 KB

Drive PhantomJS 1.8+ from Node.js using Selenium's WebDriver

License: Apache License 2.0

selenium-node-webdriver's Introduction

selenium-node-webdriver

Drive PhantomJS 1.8+ from Node.js using Selenium's WebDriver

This module provides a simple wrapper around the Node.js WebDriver implementation that ships with Selenium.

Prerequisites

Installation

npm install selenium-node-webdriver

Usage

phantomjs --webdriver=4444 &
node node_modules/selenium-node-webdriver/examples/hello.js

This example (examples/hello.js) queries Google for 'webdriver' and returns the titles of the results.

var webdriver = require('selenium-node-webdriver');

webdriver().
    then(function (driver) {
        driver.get('http://www.google.com').
            then(function () {
                return driver.
                    findElement(driver.webdriver.By.name('q')).
                    sendKeys('webdriver');
            }).
            then(function () {
                return driver.
                    findElement(driver.webdriver.By.name('btnG')).click();
            }).
            then(function () {
                return driver.executeScript(function () {
                    return Array.prototype.slice.
                        call(document.querySelectorAll('h3.r')).
                        map(function (result) {
                            return result.textContent;
                        });
                });
            }).
            then(function (results) {
                results.forEach(function (result) {
                    console.log(result);
                });
                driver.quit();
            });
    });

API

require('selenium-node-webdriver')(config <object>) -> Promise

The module exports a factory function which accepts a config object and returns a promise. The config object has two properties, both of which are optional:

server: describes the WebDriver server to connect to; it has the following properties:

  • host: the server's hostname (localhost)
  • port: the port to connect to (4444)
  • retries: the number of times to try to connect to the server (5)
  • delay: the delay in ms between connection attempts (500)

capabilities: describes the capabilities of the WebDriver client you are creating. It has the following properties by default:

  • browserName: 'chrome'
  • version: ''
  • platform: 'ANY'
  • javascriptEnabled: true

The returned promise is resolved with a RemoteWebDriver instance if the connection succeeds or rejected with the error from the final retry if connection fails.

Useful documentation

Selenium

WebDriverJS: an introduction to using JavaScript as a WebDriver client

The WebDriver Protocol

License

Apache License, Version 2.0

selenium-node-webdriver's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.