Skip to main content

AccordionElement

Playwright element wrapper for <vaadin-accordion> providing helpers to access panels by summary text and assert open/closed state.

Component Tag

vaadin-accordion

Implements

  • HasStyleElement - CSS class and style management

Constructor

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

Methods

getPanel

Get a panel by its summary text.
AccordionPanelElement getPanel(String summary)
summary
String
Panel summary text
Returns an AccordionPanelElement for the matching panel.

openPanel

Open a panel by its summary text.
void openPanel(String summary)
summary
String
Panel summary text

closePanel

Close a panel by its summary text.
void closePanel(String summary)
summary
String
Panel summary text

isPanelOpened

Whether the panel with the given summary is open.
boolean isPanelOpened(String summary)
summary
String
Panel summary text

getOpenedPanel

Get the currently opened panel.
AccordionPanelElement getOpenedPanel()
Returns the AccordionPanelElement that is currently open.

Assertion Methods

assertPanelCount

Assert the number of panels present in the accordion.
void assertPanelCount(int count)
count
int
Expected panel count

assertPanelOpened

Assert that the panel with the given summary is open.
void assertPanelOpened(String summary)
summary
String
Panel summary text

assertPanelClosed

Assert that the panel with the given summary is closed.
void assertPanelClosed(String summary)
summary
String
Panel summary text

Usage Examples

Basic Accordion Operations

AccordionElement accordion = new AccordionElement(page.locator(".custom-css"));
accordion.assertPanelCount(4);

// Check first panel is open
AccordionPanelElement panel1 = accordion.getPanel("Panel 1");
panel1.assertOpened();
panel1.assertContentVisible();

Open/Close Panels

AccordionElement accordion = new AccordionElement(page.locator("vaadin-accordion").first());

AccordionPanelElement panel2 = accordion.getPanel("Panel 2");
panel2.assertClosed();

// Opening panel 2 closes panel 1
accordion.openPanel("Panel 2");
panel1.assertClosed();
panel2.assertOpened();

Work with Disabled Panels

AccordionPanelElement disabledPanel = accordion.getPanel("Disabled Panel");
disabledPanel.assertDisabled();
disabledPanel.assertClosed();

// Clicking disabled panel has no effect
disabledPanel.getSummaryLocator().click();
disabledPanel.assertClosed();

Get Currently Opened Panel

accordion.openPanel("Panel 2");
AccordionPanelElement openedPanel = accordion.getOpenedPanel();
assertEquals("Panel 2", openedPanel.getSummaryText());

Access Panel Content

AccordionPanelElement panel = accordion.getPanel("Panel 1");
panel.assertOpened();
panel.assertContentVisible();
assertThat(panel.getContentLocator()).hasText("Content 1");

Build docs developers (and LLMs) love