Skip to main content

TabElement

Playwright element wrapper for <vaadin-tab> within a TabSheet or Tabs component.

Component Tag

vaadin-tab
  • vaadin-tabs - Parent tabs container

Constructor

locator
Locator
required
Playwright locator for the <vaadin-tab> element

Static Factory Methods

getTabByText

Get a tab by visible text within a scope.
TabElement.getTabByText(Locator locator, String summary)
locator
Locator
Scope to search within (typically tabsheet or tabs element)
summary
String
Tab text content

getSelectedTab

Get the currently selected tab within a scope.
TabElement.getSelectedTab(Locator locator)
locator
Locator
Scope to search within (typically tabsheet or tabs element)

Methods

isSelected

Whether the tab is currently selected.
boolean isSelected()

select

Select the tab by clicking it.
void select()

getLabel

Get the tab label text.
String getLabel()

Assertion Methods

assertSelected

Assert that the tab is selected.
void assertSelected()

assertNotSelected

Assert that the tab is not selected.
void assertNotSelected()

Usage Examples

Basic Tab Selection

TabSheetElement tabSheet = TabSheetElement.get(page);

TabElement tab = tabSheet.getTab("Details");
tab.assertNotSelected();
tab.select();
tab.assertSelected();

Check Tab Label

TabElement tab = tabSheet.getTab("Settings");
String label = tab.getLabel();
assertEquals("Settings", label);

Verify Selected Tab

TabSheetElement tabSheet = TabSheetElement.get(page);
TabElement selectedTab = tabSheet.getSelectedTab();

if (selectedTab.isSelected()) {
    String label = selectedTab.getLabel();
    System.out.println("Currently viewing: " + label);
}

Switch Between Tabs

TabSheetElement tabSheet = TabSheetElement.get(page);

TabElement overview = tabSheet.getTab("Overview");
TabElement details = tabSheet.getTab("Details");

overview.assertSelected();
details.assertNotSelected();

details.select();
overview.assertNotSelected();
details.assertSelected();

Use Static Factory Methods

Locator tabsLocator = page.locator("vaadin-tabsheet").first();

// Get by text
TabElement tab = TabElement.getTabByText(tabsLocator, "Settings");
tab.select();

// Get selected
TabElement selected = TabElement.getSelectedTab(tabsLocator);
assertEquals("Settings", selected.getLabel());

Build docs developers (and LLMs) love