angularjs – 我应该使用id来定位元素吗?

开始使用Angular和Protractor.

编写一些重要的css选择器会让你感觉不对劲,这些选择器会在你改变某些东西时立即中断.
使用ID会使测试更容易.

我还没有使用任何id属性进行样式设置.使用ID进行测试是否有任何缺点我没有考虑过?

一般规则是尽可能使用ID,假设它们在DOM中是唯一的,而不是动态生成的. Quoting Jim Holmes

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

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...