Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Dropdown Tests and Input Text Improvements

XxAlonexX40fa13457609
diff --git a/tests/test_dropdown.py b/tests/test_dropdown.py
index 6534fc97c..374d43227 100644
--- a/tests/test_dropdown.py
+++ b/tests/test_dropdown.py
@@ -1,14 +1,37 @@
"""
-Minimal test for dropdown functionality.
+Test dropdown interaction functionality.
"""
import pytest
-
-
-def test_simple_assertion():
- """A simple test to verify pytest is working."""
- assert True, "Basic test should always pass"
+from browser_use.agent.service import Agent
+from browser_use.agent.views import AgentHistoryList
@pytest.mark.asyncio
-async def test_dropdown_minimal():
- """Minimal async test."""
- assert True, "Minimal async test should pass"
+async def test_dropdown(llm, browser_context):
+ """Test selecting an option from a dropdown menu."""
+ 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=browser_context,
+ )
+
+ try:
+ history: AgentHistoryList = await agent.run(20)
+ result = history.final_result()
+
+ # Verify dropdown interaction
+ assert result is not None
+ assert 'Duck' in result, "Expected 5th option 'Duck' to be selected"
+
+ # Verify dropdown state
+ element = await browser_context.get_element_by_selector('select')
+ assert element is not None, "Dropdown element should exist"
+
+ value = await element.evaluate('el => el.value')
+ assert value == '5', "Dropdown should have 5th option selected"
+
+ except Exception as e:
+ pytest.fail(f"Dropdown test failed: {str(e)}")
+ finally:
+ await browser_context.close()
diff --git a/tests/test_dropdown_complex.py b/tests/test_dropdown_complex.py
index 21e558e06..774e34203 100644
--- a/tests/test_dropdown_complex.py
+++ b/tests/test_dropdown_complex.py
@@ -1,14 +1,41 @@
"""
-Minimal test for complex dropdown functionality.
+Test complex dropdown interaction functionality.
"""
import pytest
-
-
-def test_simple_assertion():
- """A simple test to verify pytest is working."""
- assert True, "Basic test should always pass"
+from browser_use.agent.service import Agent
+from browser_use.agent.views import AgentHistoryList
@pytest.mark.asyncio
-async def test_dropdown_complex_minimal():
- """Minimal async test."""
- assert True, "Minimal async test should pass"
+async def test_dropdown_complex(llm, browser_context):
+ """Test selecting an option from a complex dropdown menu."""
+ agent = Agent(
+ task=(
+ 'go to https://codepen.io/shyam-king/pen/pvzpByJ and first get all options for the dropdown and then select the json option'
+ ),
+ llm=llm,
+ browser_context=browser_context,
+ )
+
+ try:
+ history: AgentHistoryList = await agent.run(20)
+ result = history.final_result()
+
+ # Verify dropdown interaction
+ assert result is not None
+ assert 'json' in result.lower(), "Expected 'json' option to be selected"
+
+ # Verify dropdown state
+ element = await browser_context.get_element_by_selector('.select-selected')
+ assert element is not None, "Custom dropdown element should exist"
+
+ text = await element.text_content()
+ assert 'json' in text.lower(), "Dropdown should display json option"
+
+ # Verify the selected option's effect
+ code_element = await browser_context.get_element_by_selector('pre code')
+ assert code_element is not None, "Code element should be visible when JSON is selected"
+
+ except Exception as e:
+ pytest.fail(f"Complex dropdown test failed: {str(e)}")
+ finally:
+ await browser_context.close()