Class Actions


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();
      
      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.
      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
      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.
      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
      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
      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
      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.
      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.
      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.
      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.
      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
    • 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
      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
      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 element-identification timeout multiplied by ten seconds.

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

      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