Skip to main content

Overview

MenuBarElement is a Playwright wrapper for the <vaadin-menu-bar> component. It provides utilities to access menu items and open submenus. Component tag: vaadin-menu-bar Implements:
  • HasThemeElement
  • HasStyleElement
  • HasAriaLabelElement

Constructors

Create a MenuBarElement from the page by locating the first <vaadin-menu-bar> element.
page
Page
required
The Playwright page instance
Create a MenuBarElement from an existing locator.
locator
Locator
required
The Playwright locator for the menu bar element

Methods

getMenuItemElement(String name)

Get a menu item by its visible label.
name
String
required
The visible label text of the menu item
Returns: MenuItemElement - The menu item element with the specified label

openSubMenu(String name)

Click a menu item to open its submenu and return the submenu overlay.
name
String
required
The visible label text of the menu item that contains a submenu
Returns: MenuElement - The opened submenu overlay

Static Factory Methods

getByLabel(Page page, String label)

Get a menu bar by its accessible label (ARIA label).
page
Page
required
The Playwright page instance
label
String
required
The accessible label of the menu bar (uses ARIA role MENUBAR)
Returns: MenuBarElement - The menu bar with the specified label

Usage Example

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

// Create menu bar from page
MenuBarElement menuBar = new MenuBarElement(page);

// Click a top-level menu item
MenuItemElement viewItem = menuBar.getMenuItemElement("View");
viewItem.click();

// Open a submenu and select an item
MenuElement shareMenu = menuBar.openSubMenu("Share");
MenuItemElement emailItem = shareMenu.getMenuItemElement("By email");
emailItem.click();

// Verify theme
menuBar.assertTheme("contrast");

// Verify CSS class
menuBar.assertCssClass("custom-menu-bar");

Build docs developers (and LLMs) love