Skip to main content

Overview

MenuItemElement is a Playwright wrapper for individual menu items <vaadin-menu-bar-button>. It represents clickable menu items within menu bars and submenu overlays. Component tag: vaadin-menu-bar-button Implements:
  • HasThemeElement
  • HasStyleElement
  • HasAriaLabelElement

Constructors

Create a MenuItemElement from an existing locator.
locator
Locator
required
The Playwright locator for the menu item element

Methods

assertExpanded()

Assert that the menu item is expanded (shows submenu). Verifies: The element has the expanded attribute.

assertCollapsed()

Assert that the menu item is collapsed (submenu is not visible). Verifies: The element does not have the expanded attribute.

Static Factory Methods

getByLabel(Locator locator, String label)

Get a menu item by its accessible label within a scope.
locator
Locator
required
The parent locator (menu bar or menu overlay) to search within
label
String
required
The accessible label of the menu item (uses ARIA role MENUITEM)
Returns: MenuItemElement - The menu item with the specified label

Usage Example

import org.vaadin.addons.dramafinder.element.MenuBarElement;
import org.vaadin.addons.dramafinder.element.MenuItemElement;

// Get menu item from menu bar
MenuBarElement menuBar = new MenuBarElement(page);
MenuItemElement viewItem = menuBar.getMenuItemElement("View");

// Click the item
viewItem.click();

// Open submenu and verify expanded state
MenuItemElement shareItem = menuBar.getMenuItemElement("Share");
shareItem.click();
shareItem.assertExpanded();

// Access items using static factory
MenuItemElement editItem = MenuItemElement.getByLabel(menuBar.getLocator(), "Edit");
editItem.click();

Build docs developers (and LLMs) love