get_attribute
Retrieve the value of a specified DOM attribute from a web element using Selenium. Provide the element strategy, value, and attribute name; optionally set a timeout.
Instructions
Return one DOM attribute for an element.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| strategy | Yes | ||
| value | Yes | ||
| attribute | Yes | ||
| timeout_seconds | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/selenium_mcp_server/server.py:149-157 (registration)The tool is registered as an MCP tool via the @mcp.tool() decorator on the get_attribute function. It delegates to browser.get_attribute via the _run helper.
@mcp.tool() def get_attribute( strategy: LocatorStrategy, value: str, attribute: str, timeout_seconds: float | None = None, ) -> dict[str, str | None]: """Return one DOM attribute for an element.""" return _run("get_attribute", browser.get_attribute, strategy, value, attribute, timeout_seconds) - Core handler implementation: finds the element using _wait_for_element, then calls Selenium's element.get_attribute(attribute) and returns the result.
def get_attribute( self, strategy: LocatorStrategy, value: str, attribute: str, timeout_seconds: float | None = None, ) -> dict[str, str | None]: with self._lock: element = self._wait_for_element(strategy, value, timeout_seconds) return {"attribute": attribute, "value": element.get_attribute(attribute)} - Input schema: requires strategy (LocatorStrategy), value (str), attribute (str), and optional timeout_seconds. Returns dict with str or None values.
def get_attribute( strategy: LocatorStrategy, value: str, attribute: str, timeout_seconds: float | None = None, ) -> dict[str, str | None]: - The _run helper wraps handler calls with error handling for BrowserError and other exceptions.
def _run(action: str, func: Any, *args: Any, **kwargs: Any) -> Any: try: return _as_dict(func(*args, **kwargs)) except BrowserError: logger.exception("Browser action failed: %s", action) raise except Exception as exc: logger.exception("Unexpected Selenium MCP error during %s", action) raise BrowserError(f"{action} failed: {exc}") from exc