Class ElementActionsHelper
java.lang.Object
com.shaft.gui.element.internal.ElementActionsHelper
Helper utilities for low-level element discovery, interaction, and reporting.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumStrategies used to extract textual content from a web element. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMasking character used when obfuscating sensitive values in logs and reports. -
Constructor Summary
ConstructorsConstructorDescriptionElementActionsHelper(boolean isSilent) Creates a new element actions helper. -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeWebElementVisibilityUsingJavascript(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, boolean desiredIsVisibleState) Changes a web element visibility state by setting inline style via JavaScript.createReportMessage(String actionName, String testData, String elementName, Boolean passFailStatus) Builds a user-facing report message for element actions.voidexecuteNativeMobileCommandUsingJavascript(org.openqa.selenium.WebDriver driver, String command, Map<String, String> parameters) Executes a native mobile JavaScript command through the driver.voidfailAction(org.openqa.selenium.WebDriver driver, String actionName, String testData, org.openqa.selenium.By elementLocator, List<List<Object>> screenshots, Throwable... rootCauseException) Reports a failed element action using explicit action metadata and optional root cause.voidfailAction(org.openqa.selenium.WebDriver driver, String testData, org.openqa.selenium.By elementLocator, Throwable... rootCauseException) Reports a failed element action with test data and optional root cause.voidfailAction(org.openqa.selenium.WebDriver driver, String testData, org.openqa.selenium.By elementLocator, List<List<Object>> attachments, Throwable... rootCauseException) Reports a failed element action with explicit attachments and optional root cause.voidfailAction(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, Throwable... rootCauseException) Reports a failed element action using inferred action name and optional root cause.getElementName(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Resolves a human-readable element name for reporting purposes.intgetElementsCount(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Returns the number of elements that match a certain elementLocatorgetMatchingElementsInformation(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, boolean checkForVisibility) Collects element-match metadata for the supplied locator.identifyUniqueElement(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Identifies a unique matching element while enforcing visibility checks.identifyUniqueElementIgnoringVisibility(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Identifies a unique matching element without visibility checks.booleanisFoundInStacktrace(Class<?> classObject, Throwable throwable) Checks whether a target class appears in the provided throwable stack trace.voidpassAction(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, String actionName, String testData, List<List<Object>> screenshots, String elementName) Reports a successful element action with optional attachments.voidpassAction(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, String testData, List<Object> screenshot, String elementName) Reports a successful element action with a single screenshot attachment.booleanperformClipboardActions(org.openqa.selenium.WebDriver driver, ClipboardAction action) Performs a keyboard-based clipboard action on the active element.reportActionResult(org.openqa.selenium.WebDriver driver, String actionName, String testData, org.openqa.selenium.By elementLocator, List<List<Object>> screenshots, String elementName, Boolean passFailStatus, Throwable... rootCauseException) Finalizes action reporting by logging formatted message and attachments.static org.openqa.selenium.WebElementsafeFindElement(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By locator) Safely callsdriver.findElement(locator), handling the infinite recursion between Selenium 4.41.0'sElementLocationand Appium java-client 10.0.0'sAppiumBy.findElements(SearchContext).static List<org.openqa.selenium.WebElement> safeFindElements(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By locator) Safely callsdriver.findElements(locator), handling the infinite recursion between Selenium 4.41.0'sElementLocationand Appium java-client 10.0.0'sAppiumBy.findElements(SearchContext).scrollToFindElement(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Scrolls through the page until the target element is found or timeout is reached.voidsubmitFormUsingJavascript(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Submits a form element using JavaScript in non-mobile executions.takeScreenshot(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, String actionName, String testData, boolean passFailStatus) Captures an action screenshot for reporting, with pass/fail aware behavior.waitForElementPresence(org.openqa.selenium.WebDriver driver, String elementReferenceScreenshot) Waits for an on-screen image reference to appear within the current viewport.waitForElementPresence(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, boolean checkForVisibility) Waits for an element to be present (and optionally visible), then returns collected metadata.booleanwaitForElementTextToBeNot(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, String textShouldNotBe) Waits until the element text differs from the specified value.booleanwaitForElementToBeClickable(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, String actionToExecute) Waits until an element is clickable and optionally performs a follow-up action.
-
Field Details
-
OBFUSCATED_STRING
Masking character used when obfuscating sensitive values in logs and reports.- See Also:
-
-
Constructor Details
-
ElementActionsHelper
public ElementActionsHelper(boolean isSilent) Creates a new element actions helper.- Parameters:
isSilent-trueto suppress non-critical report logs;falseotherwise
-
-
Method Details
-
safeFindElements
public static List<org.openqa.selenium.WebElement> safeFindElements(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By locator) Safely callsdriver.findElements(locator), handling the infinite recursion between Selenium 4.41.0'sElementLocationand Appium java-client 10.0.0'sAppiumBy.findElements(SearchContext).The normal
driver.findElements()path is attempted first. If aStackOverflowErroroccurs (caused by Appium 3.x returningInvalidArgumentExceptionfor non-W3C locator strategies, triggeringElementLocation↔AppiumByinfinite recursion), the method falls back to sending the find command directly viaAppiumDriver.execute().- Parameters:
driver- the WebDriver instancelocator- the element locator- Returns:
- the list of found elements, or an empty list if none found or an error occurs
-
safeFindElement
public static org.openqa.selenium.WebElement safeFindElement(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By locator) Safely callsdriver.findElement(locator), handling the infinite recursion between Selenium 4.41.0'sElementLocationand Appium java-client 10.0.0'sAppiumBy.findElements(SearchContext).- Parameters:
driver- the WebDriver instancelocator- the element locator- Returns:
- the found element
- Throws:
org.openqa.selenium.NoSuchElementException- if the element cannot be found- See Also:
-
waitForElementPresence
public List<Object> waitForElementPresence(org.openqa.selenium.WebDriver driver, String elementReferenceScreenshot) Waits for an on-screen image reference to appear within the current viewport.- Parameters:
driver- the active WebDriver instanceelementReferenceScreenshot- path to the reference image file- Returns:
- list containing current screenshot, reference screenshot bytes, and matched coordinates
-
waitForElementPresence
public List<Object> waitForElementPresence(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, boolean checkForVisibility) Waits for an element to be present (and optionally visible), then returns collected metadata.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target elementcheckForVisibility- whether visibility must be validated- Returns:
- element information payload used by downstream action methods
-
scrollToFindElement
public List<Object> scrollToFindElement(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Scrolls through the page until the target element is found or timeout is reached.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target element- Returns:
- element information including match count and first matched element
-
waitForElementToBeClickable
public boolean waitForElementToBeClickable(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, String actionToExecute) Waits until an element is clickable and optionally performs a follow-up action.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target elementactionToExecute- optional action name to execute after clickability is confirmed- Returns:
truewhen the element is clickable; otherwisefalse
-
waitForElementTextToBeNot
public boolean waitForElementTextToBeNot(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, String textShouldNotBe) Waits until the element text differs from the specified value.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target elementtextShouldNotBe- text value that must no longer be present- Returns:
truewhen the condition is met; otherwisefalse
-
executeNativeMobileCommandUsingJavascript
public void executeNativeMobileCommandUsingJavascript(org.openqa.selenium.WebDriver driver, String command, Map<String, String> parameters) Executes a native mobile JavaScript command through the driver.- Parameters:
driver- the active WebDriver instancecommand- mobile command expression (for example,mobile: scroll)parameters- command parameters map
-
submitFormUsingJavascript
public void submitFormUsingJavascript(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Submits a form element using JavaScript in non-mobile executions.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the form element to submit
-
changeWebElementVisibilityUsingJavascript
public void changeWebElementVisibilityUsingJavascript(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, boolean desiredIsVisibleState) Changes a web element visibility state by setting inline style via JavaScript.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target elementdesiredIsVisibleState-trueto show element;falseto hide it
-
takeScreenshot
public List<Object> takeScreenshot(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, String actionName, String testData, boolean passFailStatus) Captures an action screenshot for reporting, with pass/fail aware behavior.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target element, ornullfor full pageactionName- current action nametestData- current action test datapassFailStatus- current action status- Returns:
- screenshot attachment payload
-
getElementName
public String getElementName(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Resolves a human-readable element name for reporting purposes.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target element- Returns:
- accessible name when available; otherwise formatted locator text
-
performClipboardActions
public boolean performClipboardActions(org.openqa.selenium.WebDriver driver, ClipboardAction action) Performs a keyboard-based clipboard action on the active element.- Parameters:
driver- the active WebDriver instanceaction- clipboard action to execute- Returns:
truewhen action succeeds; otherwisefalse
-
isFoundInStacktrace
Checks whether a target class appears in the provided throwable stack trace.- Parameters:
classObject- class to search forthrowable- throwable containing stack trace frames- Returns:
truewhen class is found in the stack trace; otherwisefalse
-
identifyUniqueElement
public List<Object> identifyUniqueElement(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Identifies a unique matching element while enforcing visibility checks.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target element- Returns:
- element information payload for the matched element
-
identifyUniqueElementIgnoringVisibility
public List<Object> identifyUniqueElementIgnoringVisibility(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Identifies a unique matching element without visibility checks.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target element- Returns:
- element information payload for the matched element
-
getMatchingElementsInformation
public List<Object> getMatchingElementsInformation(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, boolean checkForVisibility) Collects element-match metadata for the supplied locator.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target elementcheckForVisibility- whether visibility must be validated- Returns:
- list containing count and resolved element details
-
getElementsCount
public int getElementsCount(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator) Returns the number of elements that match a certain elementLocator- Parameters:
driver- the current instance of Selenium WebDriverelementLocator- the locator of the webElement under test (By xpath, id, selector, name ...etc.)- Returns:
- integer value that represents the number of elements that match the desired elementLocator
-
passAction
public void passAction(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, String testData, List<Object> screenshot, String elementName) Reports a successful element action with a single screenshot attachment.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target elementtestData- test data associated with the actionscreenshot- screenshot attachment payloadelementName- resolved element name for reporting
-
passAction
public void passAction(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, String actionName, String testData, List<List<Object>> screenshots, String elementName) Reports a successful element action with optional attachments.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target elementactionName- action name to reporttestData- test data associated with the actionscreenshots- screenshot attachments payloadelementName- resolved element name for reporting
-
failAction
public void failAction(org.openqa.selenium.WebDriver driver, org.openqa.selenium.By elementLocator, Throwable... rootCauseException) Reports a failed element action using inferred action name and optional root cause.- Parameters:
driver- the active WebDriver instanceelementLocator- locator of the target elementrootCauseException- optional root cause exceptions
-
failAction
public void failAction(org.openqa.selenium.WebDriver driver, String testData, org.openqa.selenium.By elementLocator, Throwable... rootCauseException) Reports a failed element action with test data and optional root cause.- Parameters:
driver- the active WebDriver instancetestData- test data associated with the actionelementLocator- locator of the target elementrootCauseException- optional root cause exceptions
-
failAction
public void failAction(org.openqa.selenium.WebDriver driver, String testData, org.openqa.selenium.By elementLocator, List<List<Object>> attachments, Throwable... rootCauseException) Reports a failed element action with explicit attachments and optional root cause.- Parameters:
driver- the active WebDriver instancetestData- test data associated with the actionelementLocator- locator of the target elementattachments- pre-collected attachmentsrootCauseException- optional root cause exceptions
-
failAction
public void failAction(org.openqa.selenium.WebDriver driver, String actionName, String testData, org.openqa.selenium.By elementLocator, List<List<Object>> screenshots, Throwable... rootCauseException) Reports a failed element action using explicit action metadata and optional root cause.- Parameters:
driver- the active WebDriver instanceactionName- action name to reporttestData- test data associated with the actionelementLocator- locator of the target elementscreenshots- optional screenshot attachmentsrootCauseException- optional root cause exceptions
-
createReportMessage
public String createReportMessage(String actionName, String testData, String elementName, Boolean passFailStatus) Builds a user-facing report message for element actions.- Parameters:
actionName- action nametestData- action test dataelementName- resolved element namepassFailStatus- action status flag- Returns:
- formatted report message
-
reportActionResult
public String reportActionResult(org.openqa.selenium.WebDriver driver, String actionName, String testData, org.openqa.selenium.By elementLocator, List<List<Object>> screenshots, String elementName, Boolean passFailStatus, Throwable... rootCauseException) Finalizes action reporting by logging formatted message and attachments.- Parameters:
driver- the active WebDriver instanceactionName- action name, ornullto infer from stack tracetestData- action test dataelementLocator- locator of the target elementscreenshots- pre-collected screenshotselementName- resolved element namepassFailStatus- action status flagrootCauseException- optional root cause exceptions- Returns:
- final report message
-