admin管理员组

文章数量:1335560

I want to click the Facebook's Photo/video button when creating a post. The element is:

<div aria-label="Photo/video" aria-pressed="false" class="..." role="button" tabindex="0">
  <div><div><div class="..."><div class="..."><div class="...">
    <img class="..." alt="" src=".php/v3/y7/r/Ivw7nhRtXyo.png?_nc_eui2=AeHY6dd2udiKCsGGc3_l3Lj2PL4YoeGsw5I8vhih4azDks5jrq6FoGG-iYDYkCJ4e3z08U_itrGNYjc5wzxwesxH" style="height: 24px; width: 24px;">
  </div><div class="..." role="none" data-visualcompletion="ignore" style="inset: 0px;"></div></div></div></div><div><div></div></div></div></div>

According to Page interactions | Puppeteer, I think the correct code is:

await page.locator('::-p-aria([name="Photo/video"][role="button"])').click();

But it doesn't click. Changing name to label doesn't help. Do you know how to make it work?

I want to click the Facebook's Photo/video button when creating a post. The element is:

<div aria-label="Photo/video" aria-pressed="false" class="..." role="button" tabindex="0">
  <div><div><div class="..."><div class="..."><div class="...">
    <img class="..." alt="" src="https://static.xx.fbcdn/rsrc.php/v3/y7/r/Ivw7nhRtXyo.png?_nc_eui2=AeHY6dd2udiKCsGGc3_l3Lj2PL4YoeGsw5I8vhih4azDks5jrq6FoGG-iYDYkCJ4e3z08U_itrGNYjc5wzxwesxH" style="height: 24px; width: 24px;">
  </div><div class="..." role="none" data-visualcompletion="ignore" style="inset: 0px;"></div></div></div></div><div><div></div></div></div></div>

According to Page interactions | Puppeteer, I think the correct code is:

await page.locator('::-p-aria([name="Photo/video"][role="button"])').click();

But it doesn't click. Changing name to label doesn't help. Do you know how to make it work?

Share Improve this question asked Nov 20, 2024 at 16:22 OokerOoker 3,0865 gold badges39 silver badges82 bronze badges 3
  • 1 Psuedoselectors do not currently work. Use an * or whatever element tag. await page.locator('*[aria-label="Photo/video"][role="button"]') – jakob_a Commented Nov 20, 2024 at 17:36
  • this works. Is it a bug? – Ooker Commented Nov 21, 2024 at 5:52
  • You can't use the "::-p-aria" part. – jakob_a Commented Nov 22, 2024 at 13:53
Add a comment  | 

1 Answer 1

Reset to default 1

Psuedoselectors do not currently work. Use an * or whatever element tag.

await page.locator('*[aria-label="Photo/video"][role="button"]')

本文标签: javascriptHow to click an aria button with PuppeteerStack Overflow