剧作家 - 元素不可点击

Playwright - Element not Clickable

我试图点击页面上出现的图标,但是尽管尝试了我能想到的所有方法,但我仍然收到以下错误:

waiting for selector "[aria-label="Comment"]"
  selector resolved to 2 elements. Proceeding with the first one.
  selector resolved to hidden <svg role="img" width="24" height="24" fill="#8e8e8e"…>…</svg>
attempting click action
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  element is not visible
retrying click action, attempt #1
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  element is not visible
retrying click action, attempt #2
  waiting 20ms
  waiting for element to be visible, enabled and stable

等等等等等等

虽然我在 html.. 附件中看不到任何迹象,但看起来该元素已隐藏。

非常感谢任何帮助。

enter image description here

您可以使用 nth 定位器的方法来获取第二个元素:

const comment = page.locator('svg[aria-label="Comment"]').nth(1);

await comment.waitFor();
await comment.click();

请记住,这是从零开始的编号。

更短的版本

page.locator('svg[aria-label="Comment"] >> nth=1').click();