Shadow-dom support for selenium

2019-01-23 19:31发布

I am working on an automation project which uses shadow dom extensively. So every time using execute_script function to access shadow root

for eg.

root = driver.execute_script('return document.querySelector(".flex.vertical.layout").shadowRoot')

Then use the root to access the elements within. Since we have shadow roots at many levels, this is annoying me a lot. is there any better solution exist than this to access elements within shadow root?

I am using Chrome 2.20 driver.

7条回答
在下西门庆
2楼-- · 2019-01-23 20:16

Not sure it works in all browsers, but for me ::shadow works fine in chromedriver 2.38 For example:

div::shadow div span::shadow a
查看更多
登录 后发表回答