wait_for_element
Wait for a web element to exist or become visible by specifying a locator strategy, value, timeout, and visibility requirement. Ensures element is ready for interaction.
Instructions
Wait until an element exists, or until it is visible when requested.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| strategy | Yes | ||
| value | Yes | ||
| timeout_seconds | No | ||
| visible | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The wait_for_element method on BrowserManager – the main handler that waits for an element and returns a summary of it.
def wait_for_element( self, strategy: LocatorStrategy, value: str, timeout_seconds: float = 10, visible: bool = True, ) -> ElementSummary: with self._lock: element = self._wait_for_element(strategy, value, timeout_seconds, visible=visible) return self._summarize_element(element) - _wait_for_element – internal helper that uses Selenium WebDriverWait with configurable visibility/clickable conditions.
def _wait_for_element( self, strategy: LocatorStrategy, value: str, timeout_seconds: float | None, *, clickable: bool = False, visible: bool = True, ) -> WebElement: driver = self._require_driver() by = LOCATOR_MAP[strategy] timeout = timeout_seconds if timeout_seconds is not None else self._settings.page_load_timeout_seconds condition = EC.presence_of_element_located((by, value)) if clickable: condition = EC.element_to_be_clickable((by, value)) elif visible: condition = EC.visibility_of_element_located((by, value)) try: return WebDriverWait(driver, timeout).until(condition) except TimeoutException as exc: raise BrowserError(f"Element not found: {strategy}={value}") from exc - src/selenium_mcp_server/server.py:160-168 (registration)The @mcp.tool() decorator registration of wait_for_element as an MCP tool.
@mcp.tool() def wait_for_element( strategy: LocatorStrategy, value: str, timeout_seconds: float = 10, visible: bool = True, ) -> dict[str, Any]: """Wait until an element exists, or until it is visible when requested.""" return _run("wait_for_element", browser.wait_for_element, strategy, value, timeout_seconds, visible) - LocatorStrategy type definition (Literal) used as the strategy parameter schema.
LocatorStrategy = Literal[ "id", "name", "css selector", "xpath", "link text", "partial link text", "tag name", "class name", ] - ElementSummary Pydantic model – the return type schema for wait_for_element.
class ElementSummary(BaseModel): tag_name: str text: str enabled: bool displayed: bool selected: bool attributes: dict[str, Any] = Field(default_factory=dict)