Class Actions

All Implemented Interfaces:
ElementActionsContract

public class Actions extends ElementActions
Provides a fluent API for performing low-level UI interactions on web and mobile elements.

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.

  • Constructor Details

    • Actions

      public Actions()
      Creates a new Actions instance using the driver managed by the current thread's active DriverFactoryHelper.
    • Actions

      public Actions(org.openqa.selenium.WebDriver driver)
      Creates a new Actions instance wrapping the given WebDriver.
      Parameters:
      driver - the WebDriver session to use for all element interactions
    • Actions

      public Actions(org.openqa.selenium.WebDriver driver, boolean isSilent)
      Creates a new Actions instance wrapping the given WebDriver, with optional suppression of standard reporting output.
      Parameters:
      driver - the WebDriver session to use for all element interactions
      isSilent - true to suppress log and report entries for each action; false for normal reporting
    • Actions

      public Actions(DriverFactoryHelper helper)
      Creates a new Actions instance backed by the given DriverFactoryHelper, which provides access to driver configuration, synchronization settings, and screenshot utilities.
      Parameters:
      helper - the helper that owns the underlying WebDriver session
  • Method Details

    • and

      public Actions and()
      Description copied from class: FluentWebDriverAction
      Returns 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();
      
      Specified by:
      and in interface ElementActionsContract
      Overrides:
      and in class ElementActions
      Returns:
      this FluentWebDriverAction instance, enabling continued method chaining
    • hover

      @Step("Hover") public Actions hover(@NonNull @NonNull org.openqa.selenium.By locator)
      Description copied from class: ElementActions
      Hovers 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.
      Specified by:
      hover in interface ElementActionsContract
      Overrides:
      hover in class ElementActions
      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

      @Step("Click") public Actions click(@NonNull @NonNull org.openqa.selenium.By locator)
      Description copied from class: ElementActions
      Clicks on a certain element using Selenium WebDriver, or JavaScript
      Specified by:
      click in interface ElementActionsContract
      Overrides:
      click in class ElementActions
      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: ElementActions
      Waits for the element to be clickable, and then clicks and holds it.
      Specified by:
      clickAndHold in interface ElementActionsContract
      Overrides:
      clickAndHold in class ElementActions
      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

      @Step("Double click") public Actions doubleClick(@NonNull @NonNull org.openqa.selenium.By locator)
      Description copied from class: ElementActions
      Double-clicks on an element using Selenium WebDriver's Actions Library
      Specified by:
      doubleClick in interface ElementActionsContract
      Overrides:
      doubleClick in class ElementActions
      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: ElementActions
      Clicks on certain element using javaScript only
      Specified by:
      clickUsingJavascript in interface ElementActionsContract
      Overrides:
      clickUsingJavascript in class ElementActions
      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: ElementActions
      Used to SetProperty value for an element (hidden or visible) using javascript
      Specified by:
      setValueUsingJavaScript in interface ElementActionsContract
      Overrides:
      setValueUsingJavaScript in class ElementActions
      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

      @Beta @Step("Click") public Actions click(@NonNull @NonNull String elementName)
      Clicks a clickable element resolved by its visible label or accessible name.

      This is a Beta smart-locator overload: SHAFT resolves the element automatically using SmartLocators.clickableField(String), so no explicit By locator is required.

      driver.element().click("Submit");
      
      Parameters:
      elementName - the visible text, label, or accessible name of the target element
      Returns:
      this Actions instance for fluent chaining
    • type

      @Step("Type") public Actions type(@NonNull @NonNull org.openqa.selenium.By locator, @NonNull @NonNull CharSequence... text)
      Description copied from class: ElementActions
      Types the provided text into the target element, replacing any existing value.
      Specified by:
      type in interface ElementActionsContract
      Overrides:
      type in class ElementActions
      Parameters:
      locator - the locator of the webElement under test (By xpath, id, selector, name, etc.)
      text - one or more CharSequence values (including Keys) 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 Beta smart-locator overload: SHAFT resolves the element automatically using SmartLocators.inputField(String), so no explicit By locator 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 field
      text - the character sequence(s) to type; supports Keys chords
      Returns:
      this Actions instance 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: ElementActions
      Checks 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.
      Specified by:
      typeSecure in interface ElementActionsContract
      Overrides:
      typeSecure in class ElementActions
      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: ElementActions
      Appends the required string into the target element, regardless of the current text value.
      Specified by:
      typeAppend in interface ElementActionsContract
      Overrides:
      typeAppend in class ElementActions
      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

      @Step("Clear") public Actions clear(@NonNull @NonNull org.openqa.selenium.By locator)
      Description copied from class: ElementActions
      Clears the value of the target element.
      Specified by:
      clear in interface ElementActionsContract
      Overrides:
      clear in class ElementActions
      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 drops
      filePath - the path to the local file to upload (relative or absolute)
      Returns:
      this Actions instance for fluent chaining
    • scrollToElement

      @Step("Scroll to element") public Actions scrollToElement(org.openqa.selenium.By elementLocator)
      Description copied from class: ElementActions
      If the element is outside the viewport, scrolls the bottom of the element to the bottom of the viewport.
      Specified by:
      scrollToElement in interface ElementActionsContract
      Overrides:
      scrollToElement in class ElementActions
      Parameters:
      elementLocator - the locator of the webElement under test (By xpath, id, selector, name ...etc.)
      Returns:
      a self-reference to be used to chain actions
    • select

      @Step("Select") public Actions select(org.openqa.selenium.By elementLocator, String valueOrVisibleText)
      Description copied from class: ElementActions
      Selects an element from a dropdown list using its displayed text or attribute Value
      Specified by:
      select in interface ElementActionsContract
      Overrides:
      select in class ElementActions
      Parameters:
      elementLocator - the locator of the webElement under test (By xpath, id, selector, name ...etc.)
      valueOrVisibleText - the text of the choice that you need to select from the target dropDown menu or the string value of attribute "value"
      Returns:
      a self-reference to be used to chain actions
    • submitFormUsingJavaScript

      @Step("Submit form using JavaScript") public Actions submitFormUsingJavaScript(org.openqa.selenium.By elementLocator)
      Description copied from class: ElementActions
      Used to submit a form using javascript
      Specified by:
      submitFormUsingJavaScript in interface ElementActionsContract
      Overrides:
      submitFormUsingJavaScript in class ElementActions
      Parameters:
      elementLocator - the locator of the webElement under test (By xpath, id, selector, name ...etc.)
      Returns:
      a self-reference to be used to chain actions
    • switchToIframe

      @Step("Switch to iframe") public Actions switchToIframe(org.openqa.selenium.By elementLocator)
      Description copied from class: ElementActions
      Switches focus to a certain iFrame, is mainly used in coordination with ElementActions.switchToDefaultContent() to navigate inside any iFrame layer and go back to the main page
      Specified by:
      switchToIframe in interface ElementActionsContract
      Overrides:
      switchToIframe in class ElementActions
      Parameters:
      elementLocator - the locator of the iFrame webElement under test (By xpath, id, selector, name ...etc.)
      Returns:
      a self-reference to be used to chain actions
    • typeFileLocationForUpload

      @Step("Type file location for upload") public Actions typeFileLocationForUpload(org.openqa.selenium.By elementLocator, String filePath)
      Description copied from class: ElementActions
      ValidationEnums the required file path into an input[type='file'] button, to successfully upload the target file.
      Specified by:
      typeFileLocationForUpload in interface ElementActionsContract
      Overrides:
      typeFileLocationForUpload in class ElementActions
      Parameters:
      elementLocator - the locator of the webElement under test (By xpath, id, selector, name ...etc.)
      filePath - the full path to the file that needs to be uploaded, it can be absolute or relative path, Engine will detect that.
      Returns:
      a self-reference to be used to chain actions.
    • captureScreenshot

      @Step("Capture screenshot") public Actions captureScreenshot(org.openqa.selenium.By elementLocator)
      Description copied from class: ElementActions
      Captures a screenshot of the specified element and attaches it to the test report.
      Specified by:
      captureScreenshot in interface ElementActionsContract
      Overrides:
      captureScreenshot in class ElementActions
      Parameters:
      elementLocator - the locator of the element to screenshot
      Returns:
      an Actions instance for chaining further actions
      See Also:
    • 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: ElementActions
      Drags the source element and drops it onto the destination element
      Specified by:
      dragAndDrop in interface ElementActionsContract
      Overrides:
      dragAndDrop in class ElementActions
      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: ElementActions
      Drags the source element and drops it onto the determined offset
      Specified by:
      dragAndDropByOffset in interface ElementActionsContract
      Overrides:
      dragAndDropByOffset in class ElementActions
      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 moved
      yOffset - the vertical offset by which the element should be moved
      Returns:
      a self-reference to be used to chain actions
    • get

      Returns a Actions.GetElementInformation builder 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.GetElementInformation instance scoped to this driver session
    • clipboard

      public Actions.ClipboardAction clipboard()
      Returns a Actions.ClipboardAction builder that exposes clipboard operations (copy, cut, paste, delete) for a target element.
      driver.element().clipboard().copyAll(By.id("textField"));
      
      Returns:
      a new Actions.ClipboardAction instance scoped to this driver session
    • waitUntil

      public Actions waitUntil(@NonNull @NonNull Function<? super org.openqa.selenium.WebDriver, ?> isTrue)
      Waits until the given condition returns true, using the framework's default UI state timeout.

      Delegates to waitUntil(Function, Duration) with a timeout derived from SHAFT.Properties.timeouts.waitForUiStateTimeout().

      driver.element().waitUntil(ExpectedConditions.titleContains("Dashboard"));
      
      Parameters:
      isTrue - a WebDriver condition lambda; must return a truthy value when satisfied
      Returns:
      this Actions instance 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 returns true within the specified timeout.

      Uses a fluent wait backed by the current driver session. If the condition is not satisfied before timeout elapses, a TimeoutException is 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 satisfied
      timeout - the maximum time to wait before failing
      Returns:
      this Actions instance for fluent chaining
    • executeNativeMobileCommand

      @Step("Execute native mobile command") public Actions executeNativeMobileCommand(String command, Map<String,String> parameters)
      Description copied from class: ElementActions
      This is a generic method to enable the execution of the native mobile commands found herein: appium.io

      Note: This method does no validation on the output of the executed JavaScript

      Specified by:
      executeNativeMobileCommand in interface ElementActionsContract
      Overrides:
      executeNativeMobileCommand in class ElementActions
      Parameters:
      command - the desired mobile command to be executed. e.g., "mobile: scroll"
      parameters - a map of the key, value parameters for this command. e.g., ImmutableMap.of("direction", "down")
      Returns:
      a self-reference to be used to chain actions
    • switchToDefaultContent

      @Step("Switch to default content") public Actions switchToDefaultContent()
      Description copied from class: ElementActions
      Switches focus to default content, is mainly used in coordination with ElementActions.switchToIframe(By) to exit any iFrame layer and go back to the main page
      Specified by:
      switchToDefaultContent in interface ElementActionsContract
      Overrides:
      switchToDefaultContent in class ElementActions
      Returns:
      a self-reference to be used to chain actions