# Yahoo! UI Library

### yuitest 2.5.0

Yahoo! UI Library > yuitest > YAHOO.util.UserAction

Show Private Show Protected

## `static` Class YAHOO.util.UserAction

The UserAction object provides functions that simulate events occurring in the browser. Since these are simulated events, they do not behave exactly as regular, user-initiated events do, but can be used to test simple user interactions safely.

### Methods

#### click

`static void click ( target , options )`
Simulates a click on a particular element.

Parameters:
  `target <HTMLElement>` The element to click on.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### dblclick

`static void dblclick ( target , options )`
Simulates a double click on a particular element.

Parameters:
  `target <HTMLElement>` The element to double click on.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### fireKeyEvent

`private static void fireKeyEvent ( type , target , options )`
Fires an event that normally would be fired by the keyboard (keyup, keydown, keypress). Make sure to specify either keyCode or charCode as an option.

Parameters:
  `type <String>` The type of event ("keyup", "keydown" or "keypress").
  `target <HTMLElement>` The target of the event.
  `options <Object>` Options for the event. Either keyCode or charCode are required.

Returns: `void`

#### keydown

`static void keydown ( target , options )`
Simulates a keydown event on a particular element.

Parameters:
  `target <HTMLElement>` The element to act on.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### keypress

`static void keypress ( target , options )`
Simulates a keypress on a particular element.

Parameters:
  `target <HTMLElement>` The element to act on.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### keyup

`static void keyup ( target , options )`
Simulates a keyup event on a particular element.

Parameters:
  `target <HTMLElement>` The element to act on.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### mousedown

`static void mousedown ( target , options )`
Simulates a mousedown on a particular element.

Parameters:
  `target <HTMLElement>` The element to act on.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### mouseEvent

`static void mouseEvent ( target , type , options )`
Simulates a mouse event on a particular element.

Parameters:
  `target <HTMLElement>` The element to click on.
  `type <String>` The type of event to fire. This can be any one of the following: click, dblclick, mousedown, mouseup, mouseout, mouseover, and mousemove.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### mousemove

`static void mousemove ( target , options )`
Simulates a mousemove on a particular element.

Parameters:
  `target <HTMLElement>` The element to act on.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### mouseout

`static void mouseout ( target , options )`
Simulates a mouseout event on a particular element. Use "relatedTarget" on the options object to specify where the mouse moved to. Quirks: Firefox less than 2.0 doesn't set relatedTarget properly, so toElement is assigned in its place. IE doesn't allow toElement to be be assigned, so relatedTarget is assigned in its place. Both of these concessions allow YAHOO.util.Event.getRelatedTarget() to work correctly in both browsers.

Parameters:
  `target <HTMLElement>` The element to act on.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### mouseover

`static void mouseover ( target , options )`
Simulates a mouseover event on a particular element. Use "relatedTarget" on the options object to specify where the mouse moved from. Quirks: Firefox less than 2.0 doesn't set relatedTarget properly, so fromElement is assigned in its place. IE doesn't allow fromElement to be be assigned, so relatedTarget is assigned in its place. Both of these concessions allow YAHOO.util.Event.getRelatedTarget() to work correctly in both browsers.

Parameters:
  `target <HTMLElement>` The element to act on.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### mouseup

`static void mouseup ( target , options )`
Simulates a mouseup on a particular element.

Parameters:
  `target <HTMLElement>` The element to act on.
  `options <Object>` Additional event options (use DOM standard names).

Returns: `void`

#### simulateKeyEvent

`private static void simulateKeyEvent ( target , type , bubbles , cancelable , view , ctrlKey , altKey , shiftKey , metaKey , keyCode , charCode )`
Simulates a key event using the given event information to populate the generated event object. This method does browser-equalizing calculations to account for differences in the DOM and IE event models as well as different browser quirks. Note: keydown causes Safari 2.x to crash.

Parameters:
  `target <HTMLElement>` The target of the given event.
  `type <String>` The type of event to fire. This can be any one of the following: keyup, keydown, and keypress.
  `bubbles <Boolean>` (Optional) Indicates if the event can be bubbled up. DOM Level 3 specifies that all key events bubble by default. The default is true.
  `cancelable <Boolean>` (Optional) Indicates if the event can be canceled using preventDefault(). DOM Level 3 specifies that all key events can be cancelled. The default is true.
  `view <Window>` (Optional) The view containing the target. This is typically the window object. The default is window.
  `ctrlKey <Boolean>` (Optional) Indicates if one of the CTRL keys is pressed while the event is firing. The default is false.
  `altKey <Boolean>` (Optional) Indicates if one of the ALT keys is pressed while the event is firing. The default is false.
  `shiftKey <Boolean>` (Optional) Indicates if one of the SHIFT keys is pressed while the event is firing. The default is false.
  `metaKey <Boolean>` (Optional) Indicates if one of the META keys is pressed while the event is firing. The default is false.
  `keyCode <int>` (Optional) The code for the key that is in use. The default is 0.
  `charCode <int>` (Optional) The Unicode code for the character associated with the key being used. The default is 0.

Returns: `void`

#### simulateMouseEvent

`private static void simulateMouseEvent ( target , type , bubbles , cancelable , view , detail , screenX , screenY , clientX , clientY , ctrlKey , altKey , shiftKey , metaKey , button , relatedTarget )`
Simulates a mouse event using the given event information to populate the generated event object. This method does browser-equalizing calculations to account for differences in the DOM and IE event models as well as different browser quirks.

Parameters:
  `target <HTMLElement>` The target of the given event.
  `type <String>` The type of event to fire. This can be any one of the following: click, dblclick, mousedown, mouseup, mouseout, mouseover, and mousemove.
  `bubbles <Boolean>` (Optional) Indicates if the event can be bubbled up. DOM Level 2 specifies that all mouse events bubble by default. The default is true.
  `cancelable <Boolean>` (Optional) Indicates if the event can be canceled using preventDefault(). DOM Level 2 specifies that all mouse events except mousemove can be cancelled. The default is true for all events except mousemove, for which the default is false.
  `view <Window>` (Optional) The view containing the target. This is typically the window object. The default is window.
  `detail <int>` (Optional) The number of times the mouse button has been used. The default value is 1.
  `screenX <int>` (Optional) The x-coordinate on the screen at which point the event occured. The default is 0.
  `screenY <int>` (Optional) The y-coordinate on the screen at which point the event occured. The default is 0.
  `clientX <int>` (Optional) The x-coordinate on the client at which point the event occured. The default is 0.
  `clientY <int>` (Optional) The y-coordinate on the client at which point the event occured. The default is 0.
  `ctrlKey <Boolean>` (Optional) Indicates if one of the CTRL keys is pressed while the event is firing. The default is false.
  `altKey <Boolean>` (Optional) Indicates if one of the ALT keys is pressed while the event is firing. The default is false.
  `shiftKey <Boolean>` (Optional) Indicates if one of the SHIFT keys is pressed while the event is firing. The default is false.
  `metaKey <Boolean>` (Optional) Indicates if one of the META keys is pressed while the event is firing. The default is false.
  `button <int>` (Optional) The button being pressed while the event is executing. The value should be 0 for the primary mouse button (typically the left button), 1 for the terciary mouse button (typically the middle button), and 2 for the secondary mouse button (typically the right button). The default is 0.
  `relatedTarget <HTMLElement>` (Optional) For mouseout events, this is the element that the mouse has moved to. For mouseover events, this is the element that the mouse has moved from. This argument is ignored for all other events. The default is null.

Returns: `void`

Copyright © 2007 Yahoo! Inc. All rights reserved.