在Protractor中选择一个字段

时间:2016-04-28 15:16:19

标签: protractor

<hs-details-item>
        <hs-label>Location</hs-label>
        <hs-value-block>
            <hs>
                <hs-text-box ng-class="{'disabled': isAmenityPosting }" class="required" input-control="{title:'Location', okCallback:setJobSite, value:jobSiteName,
                      autocomplete:{ values:getJobSiteList, reload: true }, ss:'location'}">
                    <i class="icon-room"></i><span hs-placeholder="Select Location" class="ng-binding"></span>
                </hs-text-box>
            </hs>
            <hs>
                <!-- ngIf: isBarcodeShow() --><hs-button ng-class="{'disabled': soCreating }" class="barcode-special-btn smaller ng-scope" ng-if="isBarcodeShow()" hs-gesture="{handler:startScan, param: onBarcodeScanCompleted}"><i class="icon-br-code"></i></hs-button><!-- end ngIf: isBarcodeShow() -->
            </hs>
        </hs-value-block>
    </hs-details-item>              

场景:点击“位置”字段... 在Protractor中选择&#34; location&#34;的最佳方法是什么?上面的代码段中的字段? 可以通过不使用Xpath来完成吗?

1 个答案:

答案 0 :(得分:0)

这里有多个选项。一种不受欢迎但又简短易读的方法是使用XPath表达式并检查前面的label

var locationTextBox = element(by.xpath("//hs-label[. = 'Location']/following::hs-text-box"));
locationTextBox.click();