0% found this document useful (0 votes)
6 views8 pages

Keyboard and Mouse Event Handling

The document outlines the Advanced User Interactions API for handling keyboard and mouse events, detailing various methods such as clickAndHold(), dragAndDrop(), and sendKeys(). It also provides a step-by-step guide for using these methods in a WebDriver context, including uploading files using sendKeys() and bypassing download dialog boxes with the wget program. Key points include the importance of importing necessary classes and the correct use of file paths in Java IDEs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

Keyboard and Mouse Event Handling

The document outlines the Advanced User Interactions API for handling keyboard and mouse events, detailing various methods such as clickAndHold(), dragAndDrop(), and sendKeys(). It also provides a step-by-step guide for using these methods in a WebDriver context, including uploading files using sendKeys() and bypassing download dialog boxes with the wget program. Key points include the importance of importing necessary classes and the correct use of file paths in Java IDEs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

KeyBoard Mouse Events

Handling special keyboard and mouse events are


done using the Advanced User Interactions API. It
contains the Actions and the Action classes that
are needed when executing these events.
Method Description
clickAndHold() Clicks (without releasing) at the current mouse location.
contextClick() Performs a context-click at the current mouse location.
doubleClick() Performs a double-click at the current mouse location.
Performs click-and-hold at the location of the source element, moves to the
location of the target element, then releases the [Link]:source-
dragAndDrop(source, target)
element to emulate button down [Link]- element to move to and release the
mouse at.

Performs click-and-hold at the location of the source element, moves by a given


dragAndDropBy(source, x-offset, y-offset) offset, then releases the [Link]:source- element to emulate button
down [Link]- horizontal move [Link]- vertical move offset.

Performs a modifier key press. Does not release the modifier key - subsequent
keyDown(modifier_key) interactions may assume it's kept [Link]:modifier_key - any of the
modifier keys ([Link], [Link], or [Link])

Performs a key [Link]:modifier_key - any of the modifier keys


keyUp(modifier _key)
([Link], [Link], or [Link])
Moves the mouse from its current position (or 0,0) by the given
[Link]:x-offset- horizontal offset. A negative value means moving the
moveByOffset(x-offset, y-offset)
mouse left.y-offset- vertical offset. A negative value means moving the mouse
up.
Moves the mouse to the middle of the element. Parameters:toElement- element
moveToElement(toElement)
to move to.
release() Releases the depressed left mouse button at the current mouse location

Sends a series of keystrokes onto the element. Parameters:onElement - element


sendKeys(onElement, charsequence) that will receive the keystrokes, usually a text fieldcharsequence - any string
value representing the sequence of keystrokes to be sent
KeyBoard Mouse Events
• Step 1
• Import the Actions and Action classes.
• Step 2
• Instantiate a new Actions object.
• Step 3
• Instantiate an Action using the Actions object in step 2.
• we are going to use the moveToElement() method because we are
simply going to mouse-over the "Home" link. The build() method is
always the final method used so that all the listed actions will be
compiled into a single step.
• Step 4
• Use the perform() method when executing the Action object we
designed in Step 3.
KeyBoard Mouse Events
• import [Link];
• import [Link];
• Actions builder = new Actions(driver);
• Action mouseOverHome = builder
• .moveToElement(link_Home)
• .build();
• [Link]();

• Fetch Background Color


• String bgColor = td_Home.getCssValue("background-
color");
Series of Multiple Actions
Uploading Files
• Uploading files in WebDriver is done by simply
using the sendKeys() method on the file-select
input field to enter the path to the file to be
uploaded.
• WebElement uploadElement =
[Link]([Link]("uploadfile_0"));

• // enter the file path onto the file-selection input
field
• [Link]("C:\\[Link]");
Uploading Files
• Remember following two things when
uploading files in WebDriver
• There is no need to simulate the clicking of
the "Browse" button. WebDriver
automatically enters the file path onto the
file-selection text box of the <input
type="file"> element
• When setting the file path in your Java
IDE, use the proper escape character for
the back-slash.
Downloading Files
• WebDriver has no capability to access the
Download dialog boxespresented by
browsers when you click on a download
link or button. However, we can bypass
these dialog boxes using a separate
program called "wget".
• Wget is a small and easy-to-use
command-line program used to automate
downloads. Basically, we will access Wget
from our WebDriver script to perform the
download process.

You might also like