Selenium C#:无法单击用户鼠标悬停时出现的#shadow-root(关闭)中的元素

Selenium C# : Not able to click on an element within #shadow-root (closed) which appears when user mouse over

我附上了我的代码截图,并用红色标记了我需要点击的元素。 在我们将鼠标悬停在另一个对象上后出现此元素 - 鼠标悬停成功,我可以看到显示此元素,但无法单击它

我的密码是

var LinksSurce = sourceThumb.FindElement(By.ID("linkSource"));
     LinksSurce.Click();     

我得到的错误是 Element not intractable

注意:我已经阅读并尝试了这些帖子中建议的解决方案,但 none 其中有效 Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click

Debugging "Element is not clickable at point" error

Selenium - Element is not clickable at point

根据您分享的屏幕截图,该元素显然位于 #shadow-root (closed).

我们讨论 Shadow DOM traversal support through 已经有一段时间了,关键要点是:

  • @43081j 提到,对于封闭的阴影根,您应该接受您无法访问它(抛出异常)。所以,我们不需要关心封闭的根,因为无论如何我们都不应该能够访问它们。
  • @AutomatedTester 在他的 spec proposal 中建议能够在 Shadow DOM 上下文和文档上下文之间移动。

因此目前您将无法与 #shadow-root (closed) 中的元素进行交互。


结论

如果 #shadow-rootopen 我们可以轻松地与所需元素进行交互。您可以在以下位置找到一些相关讨论:


备选

Shadow root DOM automation using selenium


参考资料

几个拉取请求: