What is the Advanced User Interactions - Selenium

The Advanced User Interactions API is a new, more comprehensive API for describing actions a user can perform on a web page. Normally we need to find elements and then send actions through them. If we need to perform complex tasks like hold down Control and click, then this may not work.

The Advanced User Interactions allows us to build these complex interactions with elements in a really nice API. The API relies on two key interfaces for this to work.

Keyboard

The keyboard interface allows keys to be pressed, held down, and released. It also allows for normal typing.

Methods available are:

  • voidsendKeys(CharSequence... keysToSend) : Similar to the existing sendKeys(...) method.

  • voidpressKey(Keys keyToPress) : Sends a key press only, without releasing it.
    Should only be implemented for modifier keys (Control, Alt, and Shift).

  • voidreleaseKey(Keys keyToRelease) : Releases a modifier key.

Mouse

The mouse interface allows for mouse clicks, double clicks, context clicks, as well as moving the mouse to a specific point or to a specific element on the page.

Methods available are:

  • void click(WebElementonElement):Similar to the existing click() method

  • voiddoubleClick(WebElementonElement):Double-clicks an element

  • voidmouseDown(WebElementonElement):Holds down the left mouse button on an element

  • voidmouseUp(WebElementonElement):Releases the mouse button on an element

  • voidmouseMove(WebElementtoElement): Move (from the current location)to another element

  • voidmouseMove(WebElementtoElement, long xOffset, long yOffset) :
    Move (from the current location) to new coordinates (X coordinates of toElement
    + xOffset, Y coordinates of toElement + yOffset)

  • void contextClick(WebElementonElement):Performs a context-click (right-
    click) on an element

These methods are useful to know but when working and creating a sequence of it, it is better to use the Actions chain generator and then call perform on that class.

This is the next section of the chapter.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics