Search RU
Tasks / Playwright / Keyboard navigation in a menu
Statement easy

Keyboard navigation in a menu

The page has an actions menu: a `Меню` ("Menu") button and a list of four
items — `Профиль`, `Настройки`, `Помощь`, `Выход` ("Profile", "Settings",
"Help", "Log out").

Contract:

- on load the menu is hidden and the button has `aria-expanded="false"`;
- `Tab` from the start of the page reaches the `Меню` button;
- `Enter` or `Space` on the button opens the menu: it is visible,
`aria-expanded="true"`, and focus is on the first item;
- left/right and up/down arrows move focus to the neighbouring item;
- focus wraps at the edges: left from the first item goes to the last, right
from the last goes to the first;
- `Home` — first item, `End` — last item;
- `Enter` on an item selects it: the menu closes, `status` shows
`Выбрано: <item>`, and focus returns to the button;
- `Escape` closes the menu and returns focus to the button;
- the focused item has a visible outline: `outline-style: solid`, width 2px.

Write Playwright tests:

- the menu is hidden at start;
- `Tab` reaches the button;
- opening with `Enter` and with `Space`;
- left/right/up/down arrows;
- wrapping at the edges;
- `Home` and `End`;
- selecting an item with `Enter`;
- `Escape` and focus return;
- a visible outline on the focused item.

Elements: `menu-button`, `menu`, `menu-item`, `status`. Find items with
`get_by_role("menuitem", name="...")` and the button with `get_by_test_id`.

Playwright
playwrightuikeyboardariafocus
test_ui.py Python 3.14
AI mentor

The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.

Log in and ask
Hints 1 of 3 unlocked · attempts: 0
Hint 1

How do you check where the focus actually is, and how is `aria-expanded`
different from the menu being visible?

Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts