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

Actions On Web Elements

The Actions class in Selenium is designed for advanced user interactions, allowing operations like double-clicking, right-clicking, and drag-and-drop actions. It provides greater control compared to basic WebDriver commands and includes methods for both mouse and keyboard actions. Basic commands such as click, send keys, clear, submit, and select are also available for interacting with web elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Actions On Web Elements

The Actions class in Selenium is designed for advanced user interactions, allowing operations like double-clicking, right-clicking, and drag-and-drop actions. It provides greater control compared to basic WebDriver commands and includes methods for both mouse and keyboard actions. Basic commands such as click, send keys, clear, submit, and select are also available for interacting with web elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

ACTIONS ON WEB ELEMENTS

1.Actions class in Selenium is used to perform advanced user interactions


like mouse movements and keyboard actions.

2.It enables operations such as double-click, context-click (right-click),


and drop-down selections.

3.The class provides greater control and flexibility compared to basic


WebDriver commands.

4.It allows simulation of complex interactions that are not possible with
standard WebDriver methods.
METHODS OF ACTION CLASS
 click(WebElement element) - Simulates a left-click on buttons, checkboxes, links.

 doubleClick(WebElement element) - Performs a double-click, useful for triggering


special actions.

 contextClick(WebElement element) - Executes a right-click to interact with context


menus.

 moveToElement(WebElement element) - Moves cursor to the center of an element


(e.g., hover to reveal dropdowns).

 dragAndDrop(WebElement source, WebElement target) - Drags one element and


drops it onto another (e.g., rearranging UI items).

Example :
Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.id("elementId"));
actions.click(element).build().perform();
5 Basic Commands That Can be Executed On An Element

1.click (applies to any element)

2.send keys (only applies to text fields and content editable elements)

3.clear (only applies to text fields and content editable elements)

4.submit (only applies to form elements)

5.select (see Select List Elements)


5 Basic Commands That Can be Executed On An Element

1.click (applies to any element)

2.send keys (only applies to text fields and content editable elements)

3.clear (only applies to text fields and content editable elements)

4.submit (only applies to form elements)

5.select (see Select List Elements)


1. Click - Click command is executed at the center of the element.
• If the center is obscured, Selenium throws element click intercepted error.
• Ensure the element is visible and not overlapped before using click().
WebElement element=driver.findElement(By.Id("buttonId"));
element.click();

2.Send Keys
•Sends keystrokes to an editable input field.
•Returns invalid element state error if not editable.
•Use sendKeys() only on input fields or content-editable elements.

WebElement element=driver.findElement(By.Id("inputId"));
element.sendKeys(“Hello”);
3.Clear
•Resets the content of a text field.
•Requires the element to be editable and resettable.
• Use clear() only when the input field allows content to be cleared.

WebElement element=driver.findElement(By.Id("inputId"));
element.clear();
4.Submit
•Used to submit forms to the web server.
•Can be applied to a form or any element inside a form.
•submit() is valid only for form-related elements.

WebElement form=driver.findElement(By.Id("formId"));
Form.submit();
Action class is useful mainly for mouse and keyboard actions. In order to perform such actions,
Selenium provides various methods.

Mouse Actions in Selenium:


1. doubleClick(): Performs double click on the element
2. clickAndHold(): Performs long click on the mouse without releasing it
3. dragAndDrop(): Drags the element from one point and drops to another
4. moveToElement(): Shifts the mouse pointer to the center of the element
5. contextClick(): Performs right-click on the mouse

Keyboard Actions in Selenium:


6. sendKeys(): Sends a series of keys to the element
7. keyUp(): Performs key release
8. keyDown(): Performs keypress without release

Note:
Different WebElements support different actions.
Test script developer's responsibility to ensure correct actions are applied to the target element.
If an action is unsupported, WebDriver silently ignores it without throwing an error.
Thank you!

You might also like