Polymer UI element shadow root does not support automation using selenium webdriver

北慕城南 提交于 2019-12-14 03:16:25

问题


I am facing an issue with automating polymer ui page using selenium webdriver. The reason that is blocking to start selenium automation is "shadow root" element in the polymer components. kindly suggest with some examples or ideas to overcome the issue. Does selenium supports polymer ui automation?


回答1:


No selenium doesn't support it. Either you will have to use javascript executer in selenium using documant.querySelector(...).shadowRoot or use "/deep/" combinator. The best is "/deep/ combinator" as querySelector is annoying when you are dealing with multilevel shadow DOM.

I was able to access all the shadow roots elements by

driver.find_elements_by_css_selector('body/deep/.layout.horizontal.center')

This will have access to the element with compound class name "layout horizontal center" regardless of the number of shadow roots it has.

But this only works in chrome driver and I see notes "/deep/" is a deprecated approach.

Edited on 13th Feb 2019 You can use this project https://github.com/sukgu/shadow-automation-selenium. Developed for ruby Watir framework originally and working successfully, but you can use this for selenium webdriver existing framework or any existing webdriver that supports calling javascript methods. It will shorten your testcase development time and maintenance time also. It makes your code more readable and sorted that will help you in debug time.

Worth investing your 5 minutes reading the description that shows how easy it is to integrate with your current framework or a new framework.



来源:https://stackoverflow.com/questions/50528133/polymer-ui-element-shadow-root-does-not-support-automation-using-selenium-webdri

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