问题
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