API Docs for: 0.1.0
Show:

Session Class

Defined in: lib\Session.js:40

Create a new Web Driver session

Constructor

Session

(
  • [options]
  • callback
)
async

Defined in lib\Session.js:40

Parameters:

  • [options] Object optional

    Options for WebDriver session

    • [hostname=localhost] String optional
    • [port=4444] Number optional

      Selenium server port

    • [path="/wd/hub"] String optional

      Path to Selenium server REST hub

    • [username] String optional

      Username for Basic authentication

    • [password] String optional

      Password for Basic authentication

  • callback Function

    Function context where to run WebDriver commands

Example:

   new WebDriver.Session(function() {
      this.go("http://google.com");
      if (this.title.indexOf("Google") !== -1) {
           console.log("Success!");
      }
   });
   new WebDriver.Session({
      hostname: "ondemand.saucelabs.com",
      port: 80,
      username: "<username>",
      password: "<password>"
   }, function() {
      this.url = "http://facebook.com";
   });

Methods

acceptAlert

() chainable

Defined in lib\Session.js:353

Accepts the currently displayed alert dialog. Usually, this is equivalent to clicking on the 'OK' button in the dialog.

back

() chainable

Defined in lib\Session.js:176

Navigate backwards in the browser history, if possible.

buttonDown

(
  • [button=MouseButtons.LEFT]
)
chainable

Defined in lib\Session.js:408

Click and hold the left mouse button (at the coordinates set by the last moveto command). Note that the next mouse-related command that should follow is buttonup . Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour.

Parameters:

  • [button=MouseButtons.LEFT] MouseButtons optional

    Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified.

buttonUp

(
  • [button=MouseButtons.LEFT]
)
chainable

Defined in lib\Session.js:420

Releases the mouse button previously held (where the mouse is currently at). Must be called once for every buttondown command issued. See the note in click and buttondown about implications of out-of-order commands.

Parameters:

  • [button=MouseButtons.LEFT] MouseButtons optional

    Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified.

click

(
  • [button=MouseButtons.LEFT]
)
chainable

Defined in lib\Session.js:396

Click any mouse button (at the coordinates set by the last moveto command). Note that calling this command after calling buttondown and before calling button up (or any out-of-order interactions sequence) will yield undefined behaviour).

Parameters:

  • [button=MouseButtons.LEFT] MouseButtons optional

    Which button, enum: {LEFT = 0, MIDDLE = 1 , RIGHT = 2}. Defaults to the left mouse button if not specified.

dismissAlert

() chainable

Defined in lib\Session.js:363

Dismisses the currently displayed alert dialog. For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button. For alert() dialogs, this is equivalent to clicking the 'OK' button.

doubleClick

() chainable

Defined in lib\Session.js:432

Double-clicks at the current mouse coordinates (set by moveto).

element

(
  • value
  • [using=By.cssSelector]
)
WebElement

Defined in lib\Session.js:283

Search for an element on the page, starting from the document root. The located element will be returned as a WebElement object. Each locator must return the first matching element located in the DOM.

Parameters:

  • value String

    The search target

  • [using=By.cssSelector] By optional

    The locator strategy to use.

Returns:

WebElement: A WebElement object for the located element.

elements

(
  • value
  • [using=By.cssSelector]
)
WebElement[]

Defined in lib\Session.js:302

Search for multiple elements on the page, starting from the document root. The located elements will be returned as an array of WebElement objects. Elements should be returned in the order located in the DOM.

Parameters:

  • value String

    The search target

  • [using=By.cssSelector] By optional

    The locator strategy to use.

Returns:

WebElement[]: A list of WebElements for the located elements.

execute

(
  • func
  • [args]
)

Defined in lib\Session.js:196

Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be synchronous and the result of evaluating the script is returned to the client.

Arguments may be any JSON-primitive, array, or JSON object. JSON objects that define a WebElement reference will be converted to the corresponding DOM element. Likewise, any WebElements in the script result will be returned to the client as WebElement JSON objects.

Parameters:

  • func Function

    The function to execute

  • [args] Array optional

    The function arguments

Returns:

The script result.

Example:

   var hiddenElement = this.element("#hidden");
   this.execute(function(element) {
       element.style.display = "block";
   }, hiddenElement);
   var body = this.execute(function() {
       return document.body;
   });
   this.element("body").equals(body) // true;

executeAsync

(
  • func
  • timeout=1000
  • [args]
)

Defined in lib\Session.js:227

Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be asynchronous and must signal that is done by invoking the provided callback, which is always provided as the final argument to the function. The value to this callback will be returned to the client.

Asynchronous script commands may not span page loads. If an unload event is fired while waiting for a script result, an error should be returned to the client.

The script argument defines the script to execute in the form of a function. The function will be invoked with the provided args array and the values may be accessed via the arguments object in the order specified. The final argument will always be a callback function that must be invoked to signal that the script has finished.

Arguments may be any JSON-primitive, array, or JSON object. WebElement references will be converted to the corresponding DOM element. Likewise, any WebElements in the script result will be returned to the client as WebElement objects.

Parameters:

  • func Function

    The function to execute

  • timeout=1000 Number

    Set the amount of time, in milliseconds, that asynchronous script permitted to run before they are aborted and a Timeout error is returned to the client.

  • [args] Array optional

    The function arguments

Returns:

The script result.

Example:

    var input2 = this.executeAsync(function(done) {
      window.setTimeout(function() {
          done(document.getElementById("input2"));
      }, 200);
   }, 1000);
   var asyncCalculation = this.executeAsync(function(a, b, done) {
      window.setTimeout(function() {
          done(a*b);
      }, 100);
   }, 2000, [5, 10]);
   if (asyncCalculation === 50) {
       console.log("Success! Running asynchronous code synchronously!");
   }

forward

() chainable

Defined in lib\Session.js:166

Navigate forwards in the browser history, if possible.

go

(
  • value
)
chainable

Defined in lib\Session.js:340

Navigate to a new URL.

Parameters:

  • value String

    The URL to navigate to.

Example:

this.go("http://google.com");

keys

(
  • value
)
chainable

Defined in lib\Session.js:325

Send a sequence of key strokes to the active element. This command is similar to the send keys command in every aspect except the implicit termination: The modifiers are not released at the end of the call. Rather, the state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed.

Parameters:

  • value String | String

    The keys sequence to be sent.

moveMouse

(
  • xoffset
  • yoffset
  • [element=null]
)
chainable

Defined in lib\Session.js:374

Move the mouse by an offset of the specificed element. If no element is specified, the move is relative to the current mouse cursor. If an element is provided but no offset, the mouse will be moved to the center of the element. If the element is not visible, it will be scrolled into view. For alert() dialogs, this is equivalent to clicking the 'OK' button.

Parameters:

  • xoffset Number

    X offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element.

  • yoffset Number

    Y offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element.

  • [element=null] WebElement optional

    WebElement to use for offset. If not specified or is null, the offset is relative to current position of the mouse.

refresh

() chainable

Defined in lib\Session.js:186

Refresh the current page.

screenshot

() String

Defined in lib\Session.js:274

Take a screenshot of the current page.

Returns:

String: The screenshot as a base64 encoded PNG.

Attributes

alertText

String

Defined in lib\Session.js:443

Get or set the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog.

orientation

String

Defined in lib\Session.js:481

Get or set the current browser orientation. The orientation should be specified as defined as LANDSCAPE or PORTRAIT.

title

String readonly

Defined in lib\Session.js:457

Get the current page title.

url

String

Defined in lib\Session.js:468

Get or set the url for the current window.