Actions On Web Elements
Actions On Web Elements
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.
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
2.send keys (only applies to text fields and content editable elements)
2.send keys (only applies to text fields and content editable elements)
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.
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!