Class ElementService
java.lang.Object
com.shaft.mcp.ElementService
MCP-safe element actions. Sensitive values are returned only to direct callers and are never logged.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates the default element service, wiring default Playwright/mobile services for direct Java callers and tests that construct this class without Spring. -
Method Summary
Modifier and TypeMethodDescriptionclear(locatorStrategy locatorStrategy, String locatorValue) Clears an element, dispatching to whichever engine is currently active and routing through that engine's recording wrapper when a mobile or Playwright recording is active.click(locatorStrategy locatorStrategy, String locatorValue) Java-caller convenience overload defaultingmodetoClickMode.SINGLE; not an MCP tool.click(locatorStrategy locatorStrategy, String locatorValue, ClickMode mode) Clicks an element, dispatching to whichever engine is currently active (web/mobile WebDriver or Playwright) and routing through that engine's recording wrapper when a mobile or Playwright recording is active.voidclickSemantic(String elementName) Clicks an element using SHAFT semantic locator behavior for direct Java callers.voidclickUsingAI(String elementName) Deprecated.dragAndDrop(locatorStrategy sourceLocatorStrategy, String sourceLocatorValue, locatorStrategy targetLocatorStrategy, String targetLocatorValue) Java-caller convenience overload for the element-to-element drag shape; not an MCP tool.dragAndDrop(locatorStrategy sourceLocatorStrategy, String sourceLocatorValue, locatorStrategy targetLocatorStrategy, String targetLocatorValue, Integer offsetX, Integer offsetY) Drags one element to another, or drags a source element by an offset when no target locator is given, dispatching to whichever engine is currently active.dropFileToUpload(locatorStrategy locatorStrategy, String locatorValue, String filePath) Drops a file onto an upload element, dispatching to whichever engine is currently active.getCssValue(locatorStrategy locatorStrategy, String locatorValue, String cssPropertyName) Gets a CSS value for direct Java callers.getDomAttribute(locatorStrategy locatorStrategy, String locatorValue, String domAttributeName) Gets a DOM attribute for direct Java callers.getDomProperty(locatorStrategy locatorStrategy, String locatorValue, String domPropertyName) Gets a DOM property for direct Java callers.getText(locatorStrategy locatorStrategy, String locatorValue) Gets text for direct Java callers.hover(locatorStrategy locatorStrategy, String locatorValue) Hovers over an element, dispatching to whichever engine is currently active.isDisplayed(locatorStrategy locatorStrategy, String locatorValue) Checks whether an element is displayed, dispatching to whichever engine is currently active.isEnabled(locatorStrategy locatorStrategy, String locatorValue) Checks whether an element is enabled, dispatching to whichever engine is currently active.isSelected(locatorStrategy locatorStrategy, String locatorValue) Checks whether an element (for example a checkbox or radio button) is selected, dispatching to whichever engine is currently active.type(locatorStrategy locatorStrategy, String locatorValue, String text) Java-caller convenience overload defaultingappend/clear; not an MCP tool.type(locatorStrategy locatorStrategy, String locatorValue, String text, Boolean append, Boolean clear) Types text into an element, dispatching to whichever engine is currently active and routing through that engine's recording wrapper when a mobile or Playwright recording is active.voidtypeSemantic(String elementName, CharSequence... textValue) Types text using SHAFT semantic locator behavior for direct Java callers.voidtypeUsingAI(String elementName, CharSequence... textValue) Deprecated.
-
Constructor Details
-
ElementService
public ElementService()Creates the default element service, wiring default Playwright/mobile services for direct Java callers and tests that construct this class without Spring.
-
-
Method Details
-
hover
@Tool(name="element_hover", description="hovers over an element; dispatches to the active engine and records the step when a Playwright recording is active") public ElementActionResult hover(locatorStrategy locatorStrategy, String locatorValue) Hovers over an element, dispatching to whichever engine is currently active. Mobile engines (MOBILE_NATIVE/MOBILE_WEB) share the same WebDriver-backed session as WEB and use the same code path; only Playwright uses a distinct driver instance.- Parameters:
locatorStrategy- locator strategylocatorValue- locator value- Returns:
- the active engine and, when a Playwright recording is active, the recorded step's code block
-
click
@Tool(name="element_click", description="clicks an element; optional mode selects single (default) | double | long; dispatches to the active engine and records the step when a mobile or Playwright recording is active") public ElementActionResult click(locatorStrategy locatorStrategy, String locatorValue, @ToolParam(required=false) ClickMode mode) Clicks an element, dispatching to whichever engine is currently active (web/mobile WebDriver or Playwright) and routing through that engine's recording wrapper when a mobile or Playwright recording is active.- Parameters:
locatorStrategy- locator strategylocatorValue- locator valuemode- click gesture; blank/omitted defaults toClickMode.SINGLE.ClickMode.DOUBLEandClickMode.LONGabsorb the former element_double_click/element_click_and_hold/ mobile_double_tap/mobile_long_tap tools;ClickMode.LONGis not supported on the Playwright engine.- Returns:
- the active engine and, when a recording is active, the recorded step's code block
-
click
Java-caller convenience overload defaultingmodetoClickMode.SINGLE; not an MCP tool.- Parameters:
locatorStrategy- locator strategylocatorValue- locator value- Returns:
- the active engine and, when a recording is active, the recorded step's code block
-
clickSemantic
Clicks an element using SHAFT semantic locator behavior for direct Java callers. Not exposed as an MCP tool because semantic names may contain sensitive application text.- Parameters:
elementName- semantic element name
-
clickUsingAI
Deprecated.Compatibility alias for older clients; not exposed as an MCP tool.- Parameters:
elementName- semantic element name
-
type
@Tool(name="element_type", description="types text into an element; optional append (default false) appends instead of clearing first, optional clear (default true; false behaves like append=true) controls whether the field is cleared before typing; dispatches to the active engine and records the step when a mobile or Playwright recording is active") public ElementActionResult type(locatorStrategy locatorStrategy, String locatorValue, String text, @ToolParam(required=false) Boolean append, @ToolParam(required=false) Boolean clear) Types text into an element, dispatching to whichever engine is currently active and routing through that engine's recording wrapper when a mobile or Playwright recording is active.- Parameters:
locatorStrategy- locator strategylocatorValue- locator valuetext- text to typeappend- when true, appends instead of clearing first; blank/omitted defaults to falseclear- when false, types without clearing first (equivalent toappend=true); blank/omitted defaults to true- Returns:
- the active engine and, when a recording is active, the recorded step's code block
-
type
Java-caller convenience overload defaultingappend/clear; not an MCP tool.- Parameters:
locatorStrategy- locator strategylocatorValue- locator valuetext- text to type- Returns:
- the active engine and, when a recording is active, the recorded step's code block
-
typeSemantic
Types text using SHAFT semantic locator behavior for direct Java callers. Not exposed as an MCP tool because semantic names and typed values may contain sensitive application text.- Parameters:
elementName- semantic element nametextValue- text values
-
typeUsingAI
@Deprecated(forRemoval=false) public void typeUsingAI(String elementName, CharSequence... textValue) Deprecated.Compatibility alias for older clients; not exposed as an MCP tool.- Parameters:
elementName- semantic element nametextValue- text values
-
clear
@Tool(name="element_clear", description="clears text from an element; dispatches to the active engine and records the step when a mobile or Playwright recording is active") public ElementActionResult clear(locatorStrategy locatorStrategy, String locatorValue) Clears an element, dispatching to whichever engine is currently active and routing through that engine's recording wrapper when a mobile or Playwright recording is active.- Parameters:
locatorStrategy- locator strategylocatorValue- locator value- Returns:
- the active engine and, when a recording is active, the recorded step's code block
-
dropFileToUpload
@Tool(name="element_upload_file", description="drops file to an element to upload; dispatches to the active engine and records the step when a Playwright recording is active") public ElementActionResult dropFileToUpload(locatorStrategy locatorStrategy, String locatorValue, String filePath) Drops a file onto an upload element, dispatching to whichever engine is currently active. Mobile engines (MOBILE_NATIVE/MOBILE_WEB) share the same WebDriver-backed session as WEB and use the same code path; only Playwright uses a distinct driver instance.- Parameters:
locatorStrategy- locator strategylocatorValue- locator valuefilePath- local file path- Returns:
- the active engine and, when a Playwright recording is active, the recorded step's code block
-
dragAndDrop
@Tool(name="element_drag_and_drop", description="drags and drops an element from source to a target locator, or by offsetX/offsetY when no target locator is given; dispatches to the active engine and records the step when a Playwright recording is active") public ElementActionResult dragAndDrop(locatorStrategy sourceLocatorStrategy, String sourceLocatorValue, @ToolParam(required=false) locatorStrategy targetLocatorStrategy, @ToolParam(required=false) String targetLocatorValue, @ToolParam(required=false) Integer offsetX, @ToolParam(required=false) Integer offsetY) Drags one element to another, or drags a source element by an offset when no target locator is given, dispatching to whichever engine is currently active. Mobile engines (MOBILE_NATIVE/ MOBILE_WEB) share the same WebDriver-backed session as WEB and use the same code path; only Playwright uses a distinct driver instance.- Parameters:
sourceLocatorStrategy- source locator strategysourceLocatorValue- source locator valuetargetLocatorStrategy- target locator strategy; omit together with targetLocatorValue to use offsetX/offsetY insteadtargetLocatorValue- target locator value; omit to use offsetX/offsetY insteadoffsetX- horizontal offset from the source element; used only when no target locator is givenoffsetY- vertical offset from the source element; used only when no target locator is given- Returns:
- the active engine and, when a recording is active, the recorded step's code block
-
dragAndDrop
public ElementActionResult dragAndDrop(locatorStrategy sourceLocatorStrategy, String sourceLocatorValue, locatorStrategy targetLocatorStrategy, String targetLocatorValue) Java-caller convenience overload for the element-to-element drag shape; not an MCP tool.- Parameters:
sourceLocatorStrategy- source locator strategysourceLocatorValue- source locator valuetargetLocatorStrategy- target locator strategytargetLocatorValue- target locator value- Returns:
- the active engine and, when a recording is active, the recorded step's code block
-
getText
Gets text for direct Java callers. Not exposed as an MCP tool because text may be sensitive.- Parameters:
locatorStrategy- locator strategylocatorValue- locator value- Returns:
- element text
-
getDomAttribute
public String getDomAttribute(locatorStrategy locatorStrategy, String locatorValue, String domAttributeName) Gets a DOM attribute for direct Java callers. Not exposed as an MCP tool.- Parameters:
locatorStrategy- locator strategylocatorValue- locator valuedomAttributeName- attribute name- Returns:
- attribute value
-
getDomProperty
public String getDomProperty(locatorStrategy locatorStrategy, String locatorValue, String domPropertyName) Gets a DOM property for direct Java callers. Not exposed as an MCP tool.- Parameters:
locatorStrategy- locator strategylocatorValue- locator valuedomPropertyName- property name- Returns:
- property value
-
getCssValue
public String getCssValue(locatorStrategy locatorStrategy, String locatorValue, String cssPropertyName) Gets a CSS value for direct Java callers. Not exposed as an MCP tool.- Parameters:
locatorStrategy- locator strategylocatorValue- locator valuecssPropertyName- CSS property name- Returns:
- CSS value
-
isDisplayed
@Tool(name="element_is_displayed", description="checks if an element is displayed; dispatches to the active engine") public ElementQueryResult isDisplayed(locatorStrategy locatorStrategy, String locatorValue) Checks whether an element is displayed, dispatching to whichever engine is currently active. Mobile engines (MOBILE_NATIVE/MOBILE_WEB) share the same WebDriver-backed session as WEB and use the same code path; only Playwright uses a distinct driver instance.- Parameters:
locatorStrategy- locator strategylocatorValue- locator value- Returns:
- the active engine and true when displayed
-
isEnabled
@Tool(name="element_is_enabled", description="checks if an element is enabled; dispatches to the active engine") public ElementQueryResult isEnabled(locatorStrategy locatorStrategy, String locatorValue) Checks whether an element is enabled, dispatching to whichever engine is currently active. Mobile engines (MOBILE_NATIVE/MOBILE_WEB) share the same WebDriver-backed session as WEB and use the same code path; only Playwright uses a distinct driver instance.- Parameters:
locatorStrategy- locator strategylocatorValue- locator value- Returns:
- the active engine and true when enabled
-
isSelected
@Tool(name="element_is_selected", description="checks if an element is selected; dispatches to the active engine") public ElementQueryResult isSelected(locatorStrategy locatorStrategy, String locatorValue) Checks whether an element (for example a checkbox or radio button) is selected, dispatching to whichever engine is currently active. Mobile engines (MOBILE_NATIVE/MOBILE_WEB) share the same WebDriver-backed session as WEB and use the same code path; Playwright uses a small dedicated implementation via the rawLocator.isChecked()(design doc amendment A8), since no SHAFT PlaywrightElementActionsequivalent existed before this commit.- Parameters:
locatorStrategy- locator strategylocatorValue- locator value- Returns:
- the active engine and true when selected
-