我嘗試在量角器中使用IndexOf方法。我無法將數字值改爲Promise。表Promise :: 3138 {[[PromiseStatus]]:「pending」}:無法返回數字
PsGrid.prototype.getQuickFilterByName = function(name) {
var num;
num = this.all(by.xpath(".//tr[contains(@class,'n-grid__head-row')]/th[contains(@class,'n-grid__title')]//div[contains(@class,'n-grid__text')]")).getText().then(function(textArray){
return textArray.indexOf(name) + 2;
});
expect(num).toEqual(8); // num == 2
console.log("sdf" + num); // num == Promise::3138 {[[PromiseStatus]]: "pending"}
return this.element(by.xpath('.//tr[2]/td[' + num + ']//input')); //protractor can't find element
};
完整的HTML代碼:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<table class="n-grid">
<colgroup>
<col ng-repeat="column in $view.columns track by column.$id" ps-link-element="column.elements.col" ng-attr-width="{{column.settings.width}}" class="ng-scope" width=""><col ng-repeat="column in $view.columns track by column.$id" ps-link-element="column.elements.col" ng-attr-width="{{column.settings.width}}" class="ng-scope" width="185">
<col ng-if="$view.fillerColumn.needVisible()" ng-attr-width="{{$view.fillerColumn.width}}" class="ng-scope" width="*">
</colgroup>
<thead class="n-grid__head" ps-event="{ mousedown: [
{exp: 'onMouseDown($event,column,internalOptions.states.preMoveColumn)', selector: 'div.n-grid__event'},
{exp: 'onMouseDown($event,column,internalOptions.states.resizeColumn)', selector: 'div.n-grid-col-resize'}]
}">
<tr class="n-grid__head-row" ng-show="$view.hasHeader">
<th class="n-grid__title ng-scope ng-isolate-scope n-grid__status" ng-class="column.design.classes.title" ng-repeat="column in $view.columns track by column.$id" ps-link-element="column.elements.head" on-link-element="onLinkHead(column, $last)" ps-context-menu="menuOptions.show(column, $event)" ps-grid-bind-element="column.elements.title"><span ng-if="psGrid.isMultiSelect()" class="n-grid__select-all ng-scope"></span></th><th class="n-grid__title ng-scope ng-isolate-scope" ng-class="column.design.classes.title" ng-repeat="column in $view.columns track by column.$id" ps-link-element="column.elements.head" on-link-element="onLinkHead(column, $last)" ps-context-menu="menuOptions.show(column, $event)" ps-grid-bind-element="column.elements.title">
<div class="n-grid-title-in" ng-style="{'z-index': $view.columns.length - $index}" style="z-index: 2;">
<div class="n-grid__event n-grid__event_sort" ng-class="{'n-grid__event_sort': column.sortable}">
<div class="n-grid__text ng-binding" ng-attr-title="{{column.title()}}" ng-bind="column.caption()" title="Имя клиента">Имя клиента</div>
<span class="n-grid__sort-icon"></span>
</div>
<div ng-if="column.resizable" class="n-grid-col-resize ng-scope" ng-dblclick="menuOptions.onColumnAutoSize(column)"></div>
</div>
</th><th class="n-grid__title ng-scope ng-isolate-scope n-grid__title_sortable" ng-class="column.design.classes.title" ng-repeat="column in $view.columns track by column.$id" ps-link-element="column.elements.head" on-link-element="onLinkHead(column, $last)" ps-context-menu="menuOptions.show(column, $event)" ps-grid-bind-element="column.elements.title">
<div class="n-grid-title-in" ng-style="{'z-index': $view.columns.length - $index}" style="z-index: 1;">
<div class="n-grid__event n-grid__event_sort" ng-class="{'n-grid__event_sort': column.sortable}">
<div class="n-grid__text ng-binding" ng-attr-title="{{column.title()}}" ng-bind="column.caption()" title="Номер">Номер</div>
<span class="n-grid__sort-icon"></span>
</div>
<div ng-if="column.resizable" class="n-grid-col-resize ng-scope" ng-dblclick="menuOptions.onColumnAutoSize(column)"></div>
</div>
</th>
<th ng-if="$view.fillerColumn.needVisible()" class="n-grid__title ng-scope ng-isolate-scope" ps-context-menu="">
<div class="n-grid-title-in"> </div>
</th>
</tr>
<tr ng-if="$view.hasVisibleFilters" class="n-grid__head-row ng-scope" ps-event="{ 'keydown': {exp: '$event.keyCode === 13 && $currentScope.onFilterApply()', selector: '.inp-text', apply: true},
'apply.value.component': {exp: '$currentScope.onFilterApply()', apply: true}}">
<td ng-class="column.design.classes.filter" ng-repeat="column in $view.columns track by column.$id" ps-grid-bind-element="column.elements.filter || column.elements.filter_empty" class="ng-scope n-grid__title n-grid__status"><a ng-if="$view.hasVisibleFilters" ng-click="onFilterClear()" class="n-grid__cancel-filter ng-scope" ng-attr-title="{{locale.psGrid.clearFilter}}" title="Очистить фильтр"><span class="n-grid__filter-icon"></span></a></td><td ng-class="column.design.classes.filter" ng-repeat="column in $view.columns track by column.$id" ps-grid-bind-element="column.elements.filter || column.elements.filter_empty" class="ng-scope n-grid__filter">
<input class="inp-text ng-scope ng-pristine ng-valid" ng-mousedown="in.filter.dirty.customer.filterMethod=4" ng-model="in.filter.dirty.customer.name" maxlength="64">
</td><td ng-class="column.design.classes.filter" ng-repeat="column in $view.columns track by column.$id" ps-grid-bind-element="column.elements.filter || column.elements.filter_empty" class="ng-scope n-grid__filter">
<input class="inp-text ng-scope ng-pristine ng-valid" ng-model="in.filter.dirty.inquiry.ids" ps-input-allow="/^[\s,;0-9]*$/">
</td>
<td ng-if="$view.fillerColumn.needVisible()" class="n-grid__filter ng-scope">
<span class="n-grid__empty-placeholder"> </span>
</td>
</tr>
</thead>
</table>
列名 - 「Номер」。
我試着編寫addLocator方法,但我認爲我有一些誤解。
有其他解決方案。您能發佈表格的完整HTML(包括標題)和示例「名稱」值嗎?謝謝。 – alecxe