Open eatonjl opened 1 year ago
On line 2615 of the types.d.ts file it says, "getByRole(role: "alert"|"alertdialog"|"application"|"article"|"banner"|"blockquote"|"button"|"caption"|"cell"|"checkbox"|"code"|"columnheader"|"combobox"|"complementary"|"contentinfo"|"definition"|"deletion"|"dialog"|"directory"|"document"|"emphasis"|"feed"|"figure"|"form"|"generic"|"grid"|"gridcell"|"group"|"heading"|"img"|"insertion"|"link"|"list"|"listbox"|"listitem"|"log"|"main"|"marquee"|"math"|"meter"|"menu"|"menubar"|"menuitem"|"menuitemcheckbox"|"menuitemradio"|"navigation"|"none"|"note"|"option"|"paragraph"|"presentation"|"progressbar"|"radio"|"radiogroup"|"region"|"row"|"rowgroup"|"rowheader"|"scrollbar"|"search"|"searchbox"|"separator"|"slider"|"spinbutton"|"status"|"strong"|"subscript"|"superscript"|"switch"|"tab"|"table"|"tablist"|"tabpanel"|"term"|"textbox"|"time"|"timer"|"toolbar"|"tooltip"|"tree"|"treegrid"|"treeitem", options?: {
"
You can see that "caption" is on the list.
From my testing, the name
property doesn't match when the role is set to "caption"
.
Setting the locator to await page.getByRole('caption').click();
seems to work fine, so Playwright can find the element okay.
That said, what are you trying to achieve? You're explicitly adding role="caption"
to the DOM, are you having issues with other caption locators? How does Playwright recognise them when using the "Pick locator" option in vscode?
For what it's worth: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles
Thanks for looking into it! The reason I am explicitly adding role=caption is purely for re-creation purposes. The code I am working on is not easily sharable and I didn't want to spend hours trying to find a site that had an element with role=caption. I figured this was the easiest way to reproduce the issue. I have code in our application that has role=caption and this is the outcome when testing. And you are correct about await page.getByRole('caption').click();
working. As I stated in my initial post, navigating to just the role works but trying to use a name with that specific role does not whereas it does with role=button and others. There is no mention in the documentation that some roles will work with names and others won't so I assume there could be a bug. When using the "pick locator" option it will recommend page.getbytext()
, indicating it does not recognize the role. If I change the role to a button then it recommends page.getbyrole(button, {name: [name]};
.
I did notice that Edge has an auto-complete in the inspector's element tab that shows you a list of role options. That list has the following: alert; application; article; banner; button; cell; checkbox; complementary; contentinfo; dialog; document; feed; figure; form; grid; gridcell; heading; img; list; listbox; listitem; main; navigation; region; row; rowgroup; search; switch; tab; table; tabpanel; textbox; timer
.
This means that the following may not be supported anymore?
alertdialog; blockquote; caption; code; columnheader; combobox; definition; deletion; directory; emphasis; generic; group; insertion; link; log; marquee; math; meter; menu; menubar; menuitem; menuitemcheckbox; menuitemradio; none; note; option; paragraph; presentation; progressbar; radio; radiogroup; rowheader; scrollbar; searchbox; separator; slider; spinbutton; status; strong; subscript; tablist; superscript; term; time; toolbar; tooltip; tree; treegrid; treeitem
Investigation notes. For the following snippet, there are various opinions for the roles/names.
<a id="link1" href="example.com" role="caption">NAME1</a>
<a id="link2" href="example.com" role="caption" aria-label="LABEL2">NAME2</a>
<a id="link3" href="example.com" role="term">NAME3</a>
<a id="link4" href="example.com" role="term" aria-label="LABEL4">NAME4</a>
<a id="link5" href="example.com" role="presentation">NAME5</a>
<a id="link6" href="example.com" role="presentation" aria-label="LABEL6">NAME6</a>
Role alert
also seems affected by this. I can select an element with getByRole("alert")
but am unable to select the element with getByRole("alert", { name: "<string child contents>" })
This issue seems to affect combobox and generic as well.
I can select the combobox just fine with
this.portalSwitch = page.getByRole('combobox').first();
Tests of mine that previously worked are now failing where role is set to 'generic'
But as soon as I specify the name, it fails to select the element.
@kristojorg @MaruschkaScheepersW Could you please file a new issue by filling in the "Bug Report" template and providing a repro? ARIA is full of tricky details, so we need the exact scenario to make sure there is a proper fix.
@dgozman I also ran into this issue with the combobox, I submitted a new issue with a minimal reproduction here: https://github.com/microsoft/playwright/issues/31135.
I stumbled upon this link in another thread regarding the definition
role. It seems, that both definition
and caption
both cannot be named, even though the Chrome DevTools says otherwise.
System info
Source code
Config file
Test file (self-contained)
Steps
Next Do the same thing but add "role=button" instead
Expected
both tests should pass
Actual
The first one (with "caption") fails while the second one (with "button") passes. For some reason, captions don't work even though they are listed as an option in the getbyrole description. I have gotten caption to work when I only look by role. But if I look by role AND name, it fails.