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
Test dropdown
magmueller4bdf77873f39
diff --git a/tests/test_dropdown.py b/tests/test_dropdown.pynew file mode 100644index 000000000..f3d4624e5--- /dev/null+++ b/tests/test_dropdown.py@@ -0,0 +1,45 @@+"""+Simple try of the agent.++@dev You need to add OPENAI_API_KEY to your environment variables.+"""++import os+import sys++from browser_use.browser.browser import Browser, BrowserConfig+from browser_use.browser.context import BrowserContext, BrowserContextConfig++sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+import asyncio++from langchain_openai import ChatOpenAI++from browser_use import Agent, AgentHistoryList, Controller++llm = ChatOpenAI(model='gpt-4o')+# browser = Browser(config=BrowserConfig(headless=False))++agent = Agent(+ task=(+ 'go to https://codepen.io/geheimschriftstift/pen/mPLvQz and first get all options for the dropdown and then select the 5th option'+ ),+ llm=llm,+ browser_context=BrowserContext(+ browser=Browser(config=BrowserConfig(headless=False, disable_security=True)),+ ),+)+++async def main():+ history: AgentHistoryList = await agent.run(20)+ # await controller.browser.close(force=True)++ result = history.final_result()+ assert result is not None+ assert 'Duck' in result+ input('Press Enter to close the browser')+ # await browser.close()+++asyncio.run(main())diff --git a/tests/test_vision.py b/tests/test_vision.pyindex 4fa58415f..2d3a8f05c 100644--- a/tests/test_vision.py+++ b/tests/test_vision.py@@ -10,6 +10,8 @@ import sysfrom doctest import OutputCheckerfrom pprint import pprint+from browser_use.browser.browser import Browser, BrowserConfig+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))import asyncio@@ -23,7 +25,7 @@ controller = Controller()# use this test to ask the model questions about the page like# which color do you see for bbox labels, list all with their label-# whats the smallest bboxes with labels+# whats the smallest bboxes with labels and@controller.registry.action(description='explain what you see on the screen and ask user for input')@@ -33,10 +35,17 @@ async def explain_screen(text: str) -> str:return answer[email protected](description='done')+async def done(text: str) -> str:+ # pprint(text)+ return 'call explain_screen'++agent = Agent(task='call explain_screen all the time the user asks you questions e.g. about the page like bbox which you see are labels - your task is to expalin it and get the next question',llm=llm,controller=controller,+ browser=Browser(config=BrowserConfig(disable_security=True, headless=False)),)