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

╄→гoц情女王★ 提交于 2021-02-05 06:57:45

问题


I have attached the screenshot for my code and marked the element that i need to click in red. This element appears after we mouse over on another object - and mouse over is successful and i can see this element get displayed, but failed to click on it

My code is

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

Error i am getting is Element not intractable

NOTE: i have already read and tried the solutions suggested on these posts but none of them working 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


回答1:


As per the screenshot you have shared the element is clearly within a #shadow-root (closed).

We have been discussing about Shadow DOM traversal support through Selenium for quite some time now and the key take aways are:

  • @43081j mentioned, for closed shadow roots it should just be accepted that you can't access it (throw an exception). So, we don't need to care about closed roots as we shouldn't be able to access them anyway.
  • @AutomatedTester in his spec proposal suggested the ability to move between a Shadow DOM context and the document context.

So currently you won't be able to interact with the elements within the #shadow-root (closed).


Conclusion

If the #shadow-root had been open we could have easily interacted with the desired element. You can find a couple of relevant discussions in:

  • 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?

Alternative

Shadow root DOM automation using selenium


References

A couple of pull requests:

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


来源:https://stackoverflow.com/questions/59168840/selenium-c-sharp-not-able-to-click-on-an-element-within-shadow-root-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!