Make Selenium record IDs, not paths

巧了我就是萌 提交于 2019-12-11 03:58:53

问题


When I use the FF plugin it records the paths of the elements I interact with. In cases where the DOM is heavily-altered according to the user interaction, it is more convenient to element IDs, which are guaranteed not to be affected.

I can record everything and change paths to ID manually, but I was wondering of there is a more clever way to do this?


回答1:


I don't think there is a way to do this. In my experience, you can't avoid heavy editing of test scripts for most pages that rely a lot on JS anyways (but that's of course not an answer). I often end up editing every other command (I also have had tests that I had to write in the final exported format from scratch - to allow conditions, loops and such).

Are you really creating so many scripts that this would make a difference? Is so, I guess you could modify the Selenium IDE extension (Firefox extensions are written mostly in JavaScript).




回答2:


You could explore the concept of Selenium UI-Element Locators. I haven't used it, but it looks to provide a level of abstraction against varying paths



来源:https://stackoverflow.com/questions/4919390/make-selenium-record-ids-not-paths

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