编写一些重要的css选择器会让你感觉不对劲,这些选择器会在你改变某些东西时立即中断.
使用ID会使测试更容易.
我还没有使用任何id属性进行样式设置.使用ID进行测试是否有任何缺点我没有考虑过?
Whenever possible,use ID attributes. If the page is valid HTML,then
IDs are unique on the page. They’re extraordinarily fast for
resolution in every browser,and the UI can change dramatically but
your script will still locate the element.Sometimes IDs aren’t the right choice. Dynamically generated IDs are
almost always the wrong choice when you’re working with something like
a grid control. You rely on an id that is likely tied to the specific
row position and then you’re screwed if your row changes.
此外,通常尝试使用“面向数据”的方法:by.model,by.binding,by.repeater定位器,或者如果依赖类名,请明智地选择它们:不要使用像.col这样的面向布局的类-xs-4或.container-fluid.
另请参阅以下相关主题:
> Best Practices for Watir and Selenium Locators
> best way to detect an element on a web page for seleniumRC in java