如何在带有不同文本框的相同元素的量角器中编写

时间:2018-11-19 21:41:25

标签: javascript html angularjs protractor

对于文本框,检查三个具有不同div和标记名称的文本框的元素值相同。

      <div class="input-group-addon ng-binding">NAME</div>
      <input type="text" class="form-control ng-pristine ng-valid ng-empty ng-touched" ng-class="{error:hasError(k)}" id="name" name="name" ng-model="row[k]" placeholder="0" autocomplete="off" aria-invalid="false" style="">


      <div class="input-group-addon ng-binding">SEQUENCE_NUM</div>
      <input type="text" class="form-control ng-pristine ng-valid ng-empty ng-touched" ng-class="{error:hasError(k)}" id="name" name="name" ng-model="row[k]" placeholder="0" autocomplete="off" aria-invalid="false" style="">


      <div class="input-group-addon ng-binding">VALUE</div>
      <input type="text" class="form-control ng-pristine ng-valid ng-empty ng-touched" ng-class="{error:hasError(k)}" id="name" name="name" ng-model="row[k]" placeholder="0" autocomplete="off" aria-invalid="false" style="">

名称,sequence_num和值的xpath相同// * [@@ id =“ name”]。 名称,sequence_num和值的css xpaths是相同的#name 名称,sequence_num和值的css选择器是相同的.ng-touched

很难从自动化中输入值。

如何用量角器书写?

1 个答案:

答案 0 :(得分:0)

简便的方法是在定位符中指定文本: 对于xpath://div[text()="NAME"]/following-sibling::input[@id="name"]//div[text()="SEQUENCE_NUM"]/following-sibling::input[@id="name"]//div[text()="VALUE"]/following-sibling::input[@id="name"]

正确的方法就是这样

let myLocator = label => '//div[text()="' + label + '"]/following-sibling::input[@id="name"]';

let $nameInput = element(by.xpath(myLocator("NAME")));
let $sequenceNum = element(by.xpath(myLocator("SEQUENCE_NUM")));
let $valueInput = element(by.xpath(myLocator("VALUE")));