Skip to content

Conversation

@leejamesss
Copy link

@leejamesss leejamesss commented Oct 15, 2025

Problem

Dropdown menus in Magento admin don't work, clicking them either redirects to Dashboard or does nothing.

This is related to #89, #121, and PR #112. The issue is that Playwright's accessibility tree updates before Magento's event handlers finish binding. When we click based on the tree saying an element is ready, the handlers aren't actually ready yet, so Magento's error handler kicks in and redirects.

Playwright also has a known popup menu rendering issue (microsoft/playwright#27142) that won't be fixed.

Solution

Check the element's role before clicking and handle dropdowns specially:

  • For <option> elements: Use JavaScript to set .selected and dispatch a change event directly, bypassing the accessibility tree.
  • For custom menuitems: Click the parent first, wait for initialization, then force-click the item.

Changes

Added TreeNode infrastructure to track accessibility tree relationships, then updated the CLICK handler to detect and handle dropdown elements.

Code:

node = obseration_processor.get_node_info_by_element_id(int(element_id))

if node and node.role == "option":
    page.get_by_role("option", name=node.name).evaluate(
        """(el) => {
            if (el.parentElement && el.parentElement.tagName === 'SELECT') {
                el.selected = true;
                el.parentElement.dispatchEvent(new Event('change', { bubbles: true }));
            }
        }"""
    )
elif node and node.role == "menuitem":
    if node.parent and node.parent.role in ["combobox", "button"]:
        page.get_by_role(node.parent.role, name=node.parent.name).click()
        page.wait_for_timeout(500)
    page.wait_for_timeout(300)
    page.get_by_role(node.role, name=node.name).click(force=True)

Testing

Tested in my modified environment, it fixes the dropdown issues. Can't guarantee it works in vanilla upstream though, would appreciate if you could test on the official setup, especially Magento dropdowns

References

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.

1 participant