input_text
Input text into a specified webpage element using a CSS selector. Designed for the MCP Web Browser Server to enable precise element interaction in headless browsing scenarios.
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
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | ||
| selector | Yes | ||
| text | Yes |
Input Schema (JSON Schema)
{
"properties": {
"context": {
"anyOf": [
{},
{
"type": "null"
}
],
"default": null,
"title": "Context"
},
"selector": {
"title": "Selector",
"type": "string"
},
"text": {
"title": "Text",
"type": "string"
}
},
"required": [
"selector",
"text"
],
"title": "input_textArguments",
"type": "object"
}
Implementation Reference
- src/mcp_web_browser/server.py:278-314 (handler)The handler function for the 'input_text' tool. It locates an element by CSS selector on the current page and fills it with the provided text using Playwright's fill method.@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}")