fix: preserve empty accessibility name (ax_node.name) instead of dropping it by kaXianc2-gom · Pull Request #5075 · browser-use/browser-use · GitHub
Skip to content

fix: preserve empty accessibility name (ax_node.name) instead of dropping it#5075

Open
kaXianc2-gom wants to merge 2 commits into
browser-use:mainfrom
kaXianc2-gom:fix/ax-node-empty-name
Open

fix: preserve empty accessibility name (ax_node.name) instead of dropping it#5075
kaXianc2-gom wants to merge 2 commits into
browser-use:mainfrom
kaXianc2-gom:fix/ax-node-empty-name

Conversation

@kaXianc2-gom

@kaXianc2-gom kaXianc2-gom commented Jun 21, 2026

Copy link
Copy Markdown

AI Assistance Disclosure

This contribution was developed with AI assistance (Claude / Anthropic Claude Code).

Summary

When ax_node.name is an empty string (''), the truthiness check if ax_node.name: evaluates to False, causing valid empty accessibility names to be silently dropped. An empty name and an absent name (None) carry different semantic meaning in accessibility trees.

Changes

Changed 5 instances of if .ax_node.name: to if .ax_node.name is not None: across 3 files:

  • browser_use/dom/views.py — 3 occurrences in element hashing and DOMInteractedElement.load_from_enhanced_dom_tree
  • browser_use/dom/service.py — 1 occurrence in hidden element text collection
  • browser_use/agent/service.py — 1 occurrence in AX_NAME debug logging filter

Verification Process

  1. Forked → cloned to local sandbox
  2. Created venv, installed deps (uv sync), ran existing test suite
  3. Applied fix + wrote 3 targeted unit tests in tests/ci/test_ax_name_matching.py
  4. Ran full ax_name test suite: 13/13 passed (10 existing + 3 new)
  5. Ruff format + lint: all checks passed

Test Results

tests/ci/test_ax_name_matching.py::test_ax_name_matching_succeeds_when_hash_fails PASSED
tests/ci/test_ax_name_matching.py::test_ax_name_matching_requires_same_node_type PASSED
tests/ci/test_ax_name_matching.py::test_match_level_enum_includes_ax_name PASSED
tests/ci/test_ax_name_matching.py::test_ax_name_matching_before_attribute_matching PASSED
tests/ci/test_ax_name_matching.py::test_is_menu_opener_step_detects_aria_haspopup PASSED
tests/ci/test_ax_name_matching.py::test_is_menu_opener_step_detects_guidewire_toggle PASSED
tests/ci/test_ax_name_matching.py::test_is_menu_opener_step_returns_false_for_regular_element PASSED
tests/ci/test_ax_name_matching.py::test_is_menu_item_element_detects_role_menuitem PASSED
tests/ci/test_ax_name_matching.py::test_is_menu_item_element_detects_guidewire_class PASSED
tests/ci/test_ax_name_matching.py::test_is_menu_item_element_returns_false_for_regular_element PASSED
tests/ci/test_ax_name_matching.py::test_empty_ax_name_preserved_in_load_from_enhanced_dom_tree PASSED  [NEW]
tests/ci/test_ax_name_matching.py::test_none_ax_name_preserved_in_load_from_enhanced_dom_tree PASSED  [NEW]
tests/ci/test_ax_name_matching.py::test_empty_vs_none_ax_name_produce_different_hashes PASSED  [NEW]

Cross-Validation

Scenario Before After
ax_node.name = None (no name) skipped (correct) skipped (correct)
ax_node.name = '' (empty name) ❌ dropped as falsy ✅ preserved
ax_node.name = 'Submit' (normal) ✅ preserved ✅ preserved
ax_node = None (no ax_node) short-circuits (correct) short-circuits (correct)
Empty vs None hash identical (bug) different (correct)

Closes #5041

…ping it

When ax_node.name is an empty string (''), the truthiness check
'if ax_node.name:' evaluates to False, causing valid empty accessibility
names to be silently dropped. This affects dom element hashing, hidden
element text collection, interacted element loading, and agent selectors.

Changed 5 instances of 'if .ax_node.name:' to 'if .ax_node.name is not None:'
to correctly distinguish between an absent name (None) and an explicitly
empty name (''), which carries different semantic meaning in accessibility
trees.

Files changed:
- browser_use/dom/views.py (3 occurrences in hashing methods)
- browser_use/dom/service.py (1 occurrence in hidden element text collection)
- browser_use/agent/service.py (1 occurrence in debugging ax_names filter)

Co-Authored-By: Claude <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Jun 21, 2026

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

Three new tests verify:
- Empty string ax_node.name is preserved as ax_name='' (not dropped to None)
- None ax_node.name is correctly kept as ax_name=None
- Elements with empty name vs no name produce different hashes

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Potential loss of empty accessibility names due to implicit truthiness check in views.py

2 participants