c# - Selenium C#:当用户将鼠标悬停在#shadow-root(闭合)中时,无法单击该元素-LMLPHP

我已将代码的屏幕快照附加到屏幕上,并用红色标记了需要单击的元素。
在我们将鼠标悬停在另一个对象上之后,此元素出现-鼠标悬停成功,我可以看到此元素已显示,但单击失败

我的代码是

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


我得到的错误是Element难以处理

注意:我已经阅读并尝试了这些帖子中建议的解决方案,但没有一个起作用
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讨论了Selenium一段时间了,主要的收获是:


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


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



结论

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


How to interact with the elements within #shadow-root (open) while Clearing Browsing Data of Chrome Browser using cssSelector
How to automate shadow DOM elements using selenium?




另类

Shadow root DOM automation using selenium



参考文献

几个拉取请求:


support shadow DOM when reading element text
add shadow dom v1 support to DOM atoms

关于c# - Selenium C#:当用户将鼠标悬停在#shadow-root(闭合)中时,无法单击该元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59168840/

10-14 05:10