Rayrun
← Back to Discord Forum

Selector for `[aria-haspopup=listbox]`?

Hey folks, my UI framework recently changed their dropdowns from being combobox roles to buttons with aria-haspopup="listbox". I can't seem to find a way to select this in Playwright without resorting to regular selectors. Am I SOL?

This thread is trying to answer question "How can I select a button with `aria-haspopup="listbox"` in Playwright?"

1 reply

Best I've got so far:

const buttons = page.getByRole("button", { name, ...baseOpts })

    let locator: Locator | undefined
    for (const button of await buttons.all()) {
      if ((await button.getAttribute("aria-haspopup")) === "listbox") {
        locator = locator ? locator.and(button) : button
      }
    }

    if (!locator) throw new Error(`No dropdown found for ${name}`)

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.