在很多程序员的写的时候,并没有定义id,无法通过ById这个方法去定位页面元素。
以上是我在测试中遇到的定位方法,仅供参考:
1.定位button或link,可以通过text或者partialText:
loadmodel = element(by.partialLinkText('下载模板'));
loadmodel = element(by.LinkText('下载模板'))
2.上传文件
Element(By.name("uploadfile")).sendKeys("C:\Users\123\Pictures\a.png");
3.下拉框
<select ng-model="color" ng-options="c for c in colors">
<option value="0" selected="selected">red</option>
<option value="1">green</option>
</select>
ng-model="color" ng-options="c for c in colors">
<option value="0" selected="selected">red</option>
<option value="1">green</option>
</select>
var allOptions = element.all(by.options('c for c in colors')); expect(allOptions.count()).toEqual(2); var firstOption = allOptions.first(); expect(firstOption.getText()).toEqual('red');
allOptions = element.all(by.options('c for c in colors')); expect(allOptions.count()).toEqual(2); var firstOption = allOptions.first(); expect(firstOption.getText()).toEqual('red');