Class Actions
This class extends ElementActions and adds concrete implementations for common
gestures such as clicking, typing, dragging, file uploading, and clipboard operations.
It integrates with SHAFT's reporting pipeline to attach screenshots and structured step
information to Allure reports automatically.
Actions instances are created internally by SHAFT.GUI.WebDriver and are not
intended to be constructed directly by test authors. Use the driver-level factory methods
instead:
SHAFT.GUI.WebDriver driver = new SHAFT.GUI.WebDriver();
driver.element().click(By.id("submit"));
Thread safety: Each Actions instance is tied to a single WebDriver
session. For parallel test execution, wrap driver instances in a ThreadLocal.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassProvides keyboard-shortcut-based clipboard operations for a target element.classProvides read-only accessors for querying properties, attributes, and state of a located web element. -
Constructor Summary
ConstructorsConstructorDescriptionActions()Creates a newActionsinstance using the driver managed by the current thread's activeDriverFactoryHelper.Actions(DriverFactoryHelper helper) Creates a newActionsinstance backed by the givenDriverFactoryHelper, which provides access to driver configuration, synchronization settings, and screenshot utilities.Actions(org.openqa.selenium.WebDriver driver) Creates a newActionsinstance wrapping the givenWebDriver.Actions(org.openqa.selenium.WebDriver driver, boolean isSilent) Creates a newActionsinstance wrapping the givenWebDriver, with optional suppression of standard reporting output. -
Method Summary
Modifier and TypeMethodDescriptionand()Returns this instance to allow fluent (method-chaining) syntax between successive actions.clear(@NonNull org.openqa.selenium.By locator) Clears the value of the target element.Clicks a clickable element resolved by its visible label or accessible name.click(@NonNull org.openqa.selenium.By locator) Clicks on a certain element using Selenium WebDriver, or JavaScriptclickAndHold(@NonNull org.openqa.selenium.By locator) Waits for the element to be clickable, and then clicks and holds it.clickUsingJavascript(@NonNull org.openqa.selenium.By locator) Clicks on certain element using javaScript onlyReturns aActions.ClipboardActionbuilder that exposes clipboard operations (copy, cut, paste, delete) for a target element.doubleClick(@NonNull org.openqa.selenium.By locator) Double-clicks on an element using Selenium WebDriver's Actions LibrarydragAndDrop(@NonNull org.openqa.selenium.By sourceElementLocator, @NonNull org.openqa.selenium.By destinationElementLocator) Drags the source element and drops it onto the destination elementdragAndDropByOffset(@NonNull org.openqa.selenium.By sourceElementLocator, int xOffset, int yOffset) Drags the source element and drops it onto the determined offsetdropFileToUpload(@NonNull org.openqa.selenium.By locator, @NonNull String filePath) Uploads a file by simulating a drag-and-drop gesture onto the target drop zone.get()Returns aActions.GetElementInformationbuilder that exposes read-only element property accessors such as text, attributes, CSS values, and visibility state.hover(@NonNull org.openqa.selenium.By locator) Hovers over target element.setValueUsingJavaScript(@NonNull org.openqa.selenium.By locator, @NonNull String value) Used to SetProperty value for an element (hidden or visible) using javascripttype(@NonNull String elementName, @NonNull CharSequence... text) Types the given text into an input field resolved by its visible label or placeholder.type(@NonNull org.openqa.selenium.By locator, @NonNull CharSequence... text) Types the provided text into the target element, replacing any existing value.typeAppend(@NonNull org.openqa.selenium.By locator, @NonNull CharSequence... text) Appends the required string into the target element, regardless of the current text value.typeSecure(@NonNull org.openqa.selenium.By locator, @NonNull CharSequence... text) Checks if there is any text in an element, clears it, then types the required string into the target element.Waits until the given condition returnstrue, using the framework's default element-identification timeout multiplied by ten seconds.waitUntil(@NonNull Function<? super org.openqa.selenium.WebDriver, ?> isTrue, @NonNull Duration timeout) Waits until the given condition returnstruewithin the specified timeout.Methods inherited from class ElementActions
assertThat, captureScreenshot, clipboardActions, executeNativeMobileCommand, getAttribute, getCSSProperty, getCurrentFrame, getElementsCount, getSelectedText, getTableRowsData, getText, hoverAndClick, isElementClickable, isElementDisplayed, scrollToElement, select, submitFormUsingJavaScript, switchToDefaultContent, switchToIframe, typeFileLocationForUpload, verifyThat, waitUntilAttributeContains, waitUntilElementTextToBe, waitUntilElementToBeSelected, waitUntilNumberOfElementsToBe, waitUntilNumberOfElementsToBeLessThan, waitUntilNumberOfElementsToBeMoreThan, waitUntilPresenceOfAllElementsLocatedByMethods inherited from class FluentWebDriverAction
alert, browser, element, initialize, initialize, initialize, initialize, performAlertAction, performBrowserAction, performElementAction, performTouchAction, touch
-
Constructor Details
-
Actions
public Actions()Creates a newActionsinstance using the driver managed by the current thread's activeDriverFactoryHelper. -
Actions
public Actions(org.openqa.selenium.WebDriver driver) Creates a newActionsinstance wrapping the givenWebDriver.- Parameters:
driver- the WebDriver session to use for all element interactions
-
Actions
public Actions(org.openqa.selenium.WebDriver driver, boolean isSilent) Creates a newActionsinstance wrapping the givenWebDriver, with optional suppression of standard reporting output.- Parameters:
driver- the WebDriver session to use for all element interactionsisSilent-trueto suppress log and report entries for each action;falsefor normal reporting
-
Actions
Creates a newActionsinstance backed by the givenDriverFactoryHelper, which provides access to driver configuration, synchronization settings, and screenshot utilities.- Parameters:
helper- the helper that owns the underlying WebDriver session
-
-
Method Details
-
and
Description copied from class:FluentWebDriverActionReturns this instance to allow fluent (method-chaining) syntax between successive actions. Using.and()improves readability by making multi-step test sequences read like natural language.Example:
driver.element().type(searchBox, "query") .and().browser().captureScreenshot();- Overrides:
andin classElementActions- Returns:
- this
FluentWebDriverActioninstance, enabling continued method chaining
-
hover
Description copied from class:ElementActionsHovers over target element. If you want to hover on a webElement to expose another webElement and click on it, use hoverAndClick instead for a more reliable result.- Overrides:
hoverin classElementActions- Parameters:
locator- the locator of the webElement under test (By xpath, id, selector, name ...etc.)- Returns:
- a self-reference to be used to chain actions
-
click
Description copied from class:ElementActionsClicks on a certain element using Selenium WebDriver, or JavaScript- Overrides:
clickin classElementActions- Parameters:
locator- the locator of the webElement under test (By xpath, id, selector, name ...etc.)- Returns:
- a self-reference to be used to chain actions
-
clickAndHold
@Step("Click and hold") public Actions clickAndHold(@NonNull @NonNull org.openqa.selenium.By locator) Description copied from class:ElementActionsWaits for the element to be clickable, and then clicks and holds it.- Overrides:
clickAndHoldin classElementActions- Parameters:
locator- the locator of the webElement under test (By xpath, id, selector, name ...etc.)- Returns:
- a self-reference to be used to chain actions
-
doubleClick
Description copied from class:ElementActionsDouble-clicks on an element using Selenium WebDriver's Actions Library- Overrides:
doubleClickin classElementActions- Parameters:
locator- the locator of the webElement under test (By xpath, id, selector, name ...etc.)- Returns:
- a self-reference to be used to chain actions
-
clickUsingJavascript
@Step("Click using JavaScript") public Actions clickUsingJavascript(@NonNull @NonNull org.openqa.selenium.By locator) Description copied from class:ElementActionsClicks on certain element using javaScript only- Overrides:
clickUsingJavascriptin classElementActions- Parameters:
locator- the locator of the webElement under test (By xpath, id, selector, name ...etc.)- Returns:
- a self-reference to be used to chain actions
-
setValueUsingJavaScript
@Step("Set value using JavaScript") public Actions setValueUsingJavaScript(@NonNull @NonNull org.openqa.selenium.By locator, @NonNull @NonNull String value) Description copied from class:ElementActionsUsed to SetProperty value for an element (hidden or visible) using javascript- Overrides:
setValueUsingJavaScriptin classElementActions- Parameters:
locator- the locator of the webElement under test (By xpath, id, selector, name ...etc.)value- the desired value that should be SetProperty for the target element- Returns:
- a self-reference to be used to chain actions
-
click
Clicks a clickable element resolved by its visible label or accessible name.This is a
Betasmart-locator overload: SHAFT resolves the element automatically usingSmartLocators.clickableField(String), so no explicitBylocator is required.driver.element().click("Submit");- Parameters:
elementName- the visible text, label, or accessible name of the target element- Returns:
- this
Actionsinstance for fluent chaining
-
type
@Step("Type") public Actions type(@NonNull @NonNull org.openqa.selenium.By locator, @NonNull @NonNull CharSequence... text) Description copied from class:ElementActionsTypes the provided text into the target element, replacing any existing value.- Overrides:
typein classElementActions- Parameters:
locator- the locator of the webElement under test (By xpath, id, selector, name, etc.)text- one or moreCharSequencevalues (includingKeys) to be typed into the target webElement- Returns:
- a self-reference to be used to chain actions
-
type
@Beta @Step("Type") public Actions type(@NonNull @NonNull String elementName, @NonNull @NonNull CharSequence... text) Types the given text into an input field resolved by its visible label or placeholder.This is a
Betasmart-locator overload: SHAFT resolves the element automatically usingSmartLocators.inputField(String), so no explicitBylocator is required. The field is cleared (according to the configured clear-before-typing mode) before the text is entered.driver.element().type("Search", "SHAFT Engine");- Parameters:
elementName- the visible label or placeholder of the target input fieldtext- the character sequence(s) to type; supportsKeyschords- Returns:
- this
Actionsinstance for fluent chaining
-
typeSecure
@Step("Type securely") public Actions typeSecure(@NonNull @NonNull org.openqa.selenium.By locator, @NonNull @NonNull CharSequence... text) Description copied from class:ElementActionsChecks if there is any text in an element, clears it, then types the required string into the target element. Obfuscates the written text in the output report. This action should be used for writing passwords and secure text.- Overrides:
typeSecurein classElementActions- Parameters:
locator- the locator of the webElement under test (By xpath, id, selector, name ...etc.)text- the target text that needs to be typed into the target webElement- Returns:
- a self-reference to be used to chain actions
-
typeAppend
@Step("Append") public Actions typeAppend(@NonNull @NonNull org.openqa.selenium.By locator, @NonNull @NonNull CharSequence... text) Description copied from class:ElementActionsAppends the required string into the target element, regardless of the current text value.- Overrides:
typeAppendin classElementActions- Parameters:
locator- the locator of the webElement under test (By xpath, id, selector, name ...etc.)text- the target text that needs to be appended into the target webElement- Returns:
- a self-reference to be used to chain actions
-
clear
Description copied from class:ElementActionsClears the value of the target element.- Overrides:
clearin classElementActions- Parameters:
locator- the locator of the webElement under test (By xpath, id, selector, name, etc.)- Returns:
- a self-reference to be used to chain actions
-
dropFileToUpload
@Step("Drop file to upload") public Actions dropFileToUpload(@NonNull @NonNull org.openqa.selenium.By locator, @NonNull @NonNull String filePath) Uploads a file by simulating a drag-and-drop gesture onto the target drop zone.An invisible
<input type="file">element is injected via JavaScript into the drop zone. The file path is then sent to that injected input, which triggers the browser's native file-upload mechanism without requiring the OS file-picker dialog.driver.element().dropFileToUpload(By.id("dropZone"), "src/test/resources/files/document.pdf");- Parameters:
locator- the locator for the drop-zone element that accepts file dropsfilePath- the path to the local file to upload (relative or absolute)- Returns:
- this
Actionsinstance for fluent chaining
-
dragAndDrop
@Step("Drag and drop") public Actions dragAndDrop(@NonNull @NonNull org.openqa.selenium.By sourceElementLocator, @NonNull @NonNull org.openqa.selenium.By destinationElementLocator) Description copied from class:ElementActionsDrags the source element and drops it onto the destination element- Overrides:
dragAndDropin classElementActions- Parameters:
sourceElementLocator- the locator of the source webElement that should be dragged under test (By xpath, id, selector, name ...etc.)destinationElementLocator- the locator of the target webElement that should receive the dropped source element under test (By xpath, id, selector, name ...etc.)- Returns:
- a self-reference to be used to chain actions
-
dragAndDropByOffset
@Step("Drag and drop by offset") public Actions dragAndDropByOffset(@NonNull @NonNull org.openqa.selenium.By sourceElementLocator, int xOffset, int yOffset) Description copied from class:ElementActionsDrags the source element and drops it onto the determined offset- Overrides:
dragAndDropByOffsetin classElementActions- Parameters:
sourceElementLocator- the locator of the source webElement that should be dragged under test (By xpath, id, selector, name ...etc.)xOffset- the horizontal offset by which the element should be movedyOffset- the vertical offset by which the element should be moved- Returns:
- a self-reference to be used to chain actions
-
get
Returns aActions.GetElementInformationbuilder that exposes read-only element property accessors such as text, attributes, CSS values, and visibility state.String value = driver.element().get().text(By.id("username"));- Returns:
- a new
Actions.GetElementInformationinstance scoped to this driver session
-
clipboard
Returns aActions.ClipboardActionbuilder that exposes clipboard operations (copy, cut, paste, delete) for a target element.driver.element().clipboard().copyAll(By.id("textField"));- Returns:
- a new
Actions.ClipboardActioninstance scoped to this driver session
-
waitUntil
public Actions waitUntil(@NonNull @NonNull Function<? super org.openqa.selenium.WebDriver, ?> isTrue) Waits until the given condition returnstrue, using the framework's default element-identification timeout multiplied by ten seconds.Delegates to
waitUntil(Function, Duration)with a computed timeout derived fromSHAFT.Properties.timeouts.defaultElementIdentificationTimeout().driver.element().waitUntil(ExpectedConditions.titleContains("Dashboard"));- Parameters:
isTrue- a WebDriver condition lambda; must return a truthy value when satisfied- Returns:
- this
Actionsinstance for fluent chaining
-
waitUntil
@Step("Wait until") public Actions waitUntil(@NonNull @NonNull Function<? super org.openqa.selenium.WebDriver, ?> isTrue, @NonNull @NonNull Duration timeout) Waits until the given condition returnstruewithin the specified timeout.Uses a fluent wait backed by the current driver session. If the condition is not satisfied before
timeoutelapses, aTimeoutExceptionis caught and the step is marked as broken in the Allure report.driver.element().waitUntil( ExpectedConditions.visibilityOfElementLocated(By.id("modal")), Duration.ofSeconds(30) );- Parameters:
isTrue- a WebDriver condition lambda; must return a truthy value when satisfiedtimeout- the maximum time to wait before failing- Returns:
- this
Actionsinstance for fluent chaining
-