input_text
Enter text into web page elements using CSS selectors for automated form filling or content input in browser automation workflows.
Instructions
Input text into a specific element on the page.
Args:
selector: CSS selector for the input element
text: Text to input
context: Optional context object for logging (ignored)
Returns:
Confirmation message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | Yes | ||
| text | Yes | ||
| context | No |
Implementation Reference
- src/mcp_web_browser/server.py:278-314 (handler)The `input_text` tool handler: inputs text into a form element on the current page using Playwright's `fill` method. Requires a prior `browse_to` call to load a page. Registered via `@mcp.tool()` decorator.@mcp.tool() async def input_text( selector: str, text: str, context: Optional[Any] = None ) -> str: """ Input text into a specific element on the page. Args: selector: CSS selector for the input element text: Text to input context: Optional context object for logging (ignored) Returns: Confirmation message """ global _current_page if not _current_page: raise ValueError("No page is currently loaded. Use browse_to first.") try: element = await _current_page.query_selector(selector) if not element: raise ValueError(f"No element found with selector: {selector}") await element.fill(text) print(f"Input text into element: {selector}", file=sys.stderr) return f"Successfully input text into element: {selector}" except Exception as e: print(f"Error inputting text: {e}", file=sys.stderr) raise ValueError(f"Error inputting text: {e}")