Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
add tool example browser session
Magnus Müller02e14b71e261
diff --git a/docs/customize/tools/add.mdx b/docs/customize/tools/add.mdxindex e17cbd730..564ae650e 100644--- a/docs/customize/tools/add.mdx+++ b/docs/customize/tools/add.mdx@@ -52,6 +52,45 @@ Your function has access to these objects:- **`available_file_paths: list[str]`** - Available files for upload/processing- **`has_sensitive_data: bool`** - Whether action contains sensitive data++## Browser Interaction Examples++You can use `browser_session` to directly interact with page elements using CSS selectors:++```python+from browser_use import Tools, Agent, ActionResult, BrowserSession++tools = Tools()+[email protected](description='Click the submit button using CSS selector')+async def click_submit_button(browser_session: BrowserSession):+ # Get the current page+ page = await browser_session.must_get_current_page()++ # Get element(s) by CSS selector+ elements = await page.get_elements_by_css_selector('button[type="submit"]')++ if not elements:+ return ActionResult(extracted_content='No submit button found')++ # Click the first matching element+ await elements[0].click()++ return ActionResult(extracted_content='Submit button clicked!')+```+++Available methods on `Page`:+- `get_elements_by_css_selector(selector: str)` - Returns list of matching elements+- `get_element_by_prompt(prompt: str, llm)` - Returns element or None using LLM+- `must_get_element_by_prompt(prompt: str, llm)` - Returns element or raises error++Available methods on `Element`:+- `click()` - Click the element+- `type(text: str)` - Type text into the element+- `get_text()` - Get element text content+- See `browser_use/actor/element.py` for more methods+## Pydantic InputYou can use Pydantic for the tool parameters: