Skip to content

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

Enhance error messages in dropdown and menu selection logic to include available options for better debugging. This change improves clarity when options are not found by providing a structured list of available choices.

Magnus Müllerfe438376497f
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.py
index 040985809..6e6f4dd72 100644
--- a/browser_use/controller/service.py
+++ b/browser_use/controller/service.py
@@ -916,9 +916,16 @@ Provide the extracted information in a clear, structured format."""
};
}
}
+
+ // Show all available options for debugging
+ const availableOptions = options.map(opt => ({
+ text: opt.text.trim(),
+ value: opt.value
+ }));
+
return {
success: false,
- error: `Option with text or value '${targetText}' not found in select element`
+ error: `Option with text or value '${targetText}' not found in select element. Available options: ${JSON.stringify(availableOptions, null, 2)}`
};
}
@@ -957,9 +964,16 @@ Provide the extracted information in a clear, structured format."""
}
}
}
+
+ // Show all available options for debugging
+ const availableOptions = Array.from(menuItems).map(item => ({
+ text: item.textContent ? item.textContent.trim() : '',
+ value: item.getAttribute('data-value') || ''
+ })).filter(opt => opt.text || opt.value);
+
return {
success: false,
- error: `Menu item with text or value '${targetText}' not found`
+ error: `Menu item with text or value '${targetText}' not found. Available options: ${JSON.stringify(availableOptions, null, 2)}`
};
}
@@ -1005,9 +1019,16 @@ Provide the extracted information in a clear, structured format."""
}
}
}
+
+ // Show all available options for debugging
+ const availableOptions = Array.from(menuItems).map(item => ({
+ text: item.textContent ? item.textContent.trim() : '',
+ value: item.getAttribute('data-value') || ''
+ })).filter(opt => opt.text || opt.value);
+
return {
success: false,
- error: `Custom dropdown item with text or value '${targetText}' not found`
+ error: `Custom dropdown item with text or value '${targetText}' not found. Available options: ${JSON.stringify(availableOptions, null, 2)}`
};
}