请问我有等同于对象和字符串的问题,如果同时打印两者(使用方法sendKeys();),它具有相同的值,但是这个条件是假的。当我将对象转换为字符串时未定义。 thisAdspaceNumb来自角表。我想生成ADSPACEx(如ADSPACE3,ADSPACE4 ......它是唯一的密钥)。我知道,这是获得" id"但我更喜欢子串只有键的数量并增加它。谢谢
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<table id="adspaceTable" ng-table="adspaceTable" class="table ng-scope ng-table" style="table-layout: fixed;"><!-- ngInclude: templates.header --><thead ng-include="templates.header" class="ng-scope"><tr class="ng-scope"> <!-- ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header undefined col-sm-2 ellipsing sortable sort-asc"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope">Code</div><!-- end ngIf: !template --> <!-- ngIf: template --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header undefined col-sm-3 ellipsing sortable sort-asc"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope">Name</div><!-- end ngIf: !template --> <!-- ngIf: template --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header undefined col-sm-3 ellipsing sortable"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope">Description</div><!-- end ngIf: !template --> <!-- ngIf: template --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header undefined col-sm-2 sortable ng-hide"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope">Expired</div><!-- end ngIf: !template --> <!-- ngIf: template --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-class="{ 'sortable': parse(column.sortable), 'sort-asc': params.sorting()[parse(column.sortable)]=='asc', 'sort-desc': params.sorting()[parse(column.sortable)]=='desc' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header undefined col-sm-2 nowrap"> <!-- ngIf: !template --><div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)" class="ng-binding ng-scope"> </div><!-- end ngIf: !template --> <!-- ngIf: template --> </th><!-- end ngRepeat: column in $columns --> </tr> <tr ng-show="show_filter" class="ng-table-filters ng-scope ng-hide"> <!-- ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter ng-scope"> <!-- ngRepeat: (name, filter) in column.filter --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter ng-scope"> <!-- ngRepeat: (name, filter) in column.filter --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter ng-scope"> <!-- ngRepeat: (name, filter) in column.filter --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter ng-scope ng-hide"> <!-- ngRepeat: (name, filter) in column.filter --> </th><!-- end ngRepeat: column in $columns --><th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter ng-scope"> <!-- ngRepeat: (name, filter) in column.filter --> </th><!-- end ngRepeat: column in $columns --> </tr></thead>
<tbody><!-- ngRepeat: adspace in $data --><tr ng-repeat="adspace in $data" ng-click="changeSelection(adspace, selectedAdspace.$edit)" ng-class="{'active': adspace.$selected}" class="ng-scope">
<td id="TabCode" data-title="translate('win-web-adspace.lbl-code')" class="col-sm-2 ellipsing ng-binding" sortable="'code'" data-title-text=" ">ADSPACE1</td>
<td data-title="translate('win-web-adspace.lbl-name')" class="col-sm-3 ellipsing ng-binding" sortable="'name'" data-title-text=" ">Ad Space 1</td>
<td data-title="translate('win-web-adspace.lbl-desc')" class="col-sm-3 ellipsing ng-binding" sortable="'desc'" data-title-text=" ">Ad Space 1</td>
<td ng-show="expiredFilter == 2" data-title="translate('global.lbl-expired')" class="col-sm-2 ng-hide" sortable="'expired'" data-title-text=" ">
<input type="checkbox" ng-model="adspace.adspaceExpired" ng-true-value="true" ng-false-value="false" ng-disabled="true" ng-checked="adspace.adspaceExpired" class="ng-pristine ng-valid" disabled="disabled">
</td>
<td class="col-sm-2 nowrap" data-title-text=" ">
<!-- ngIf: !selectedAdspace.$edit --><a ng-if="!selectedAdspace.$edit" class="row-icon ng-scope">
<i class="fa fa-lg fa-pencil-square-o cursor-pointer"></i>
</a><!-- end ngIf: !selectedAdspace.$edit -->
<!-- ngIf: !selectedAdspace.$edit && !adspace.expired --><!-- cawAuth: hasRole('ROLE_MC_ADM_OL_ADSPACE_D') --><a ng-really-click="deleteAdspace(adspace);" ng-really-message="This action cannot be undone. Are you sure you want to delete this?" ng-if="!selectedAdspace.$edit && !adspace.expired" class="row-icon ng-scope ng-isolate-scope" caw-auth="hasRole('ROLE_MC_ADM_OL_ADSPACE_D')">
<i class="fa fa-lg fa-times cursor-pointer"></i>
</a><!-- end cawAuth: hasRole('ROLE_MC_ADM_OL_ADSPACE_D') --><!-- end ngIf: !selectedAdspace.$edit && !adspace.expired -->
</td>
</tr><!-- end ngRepeat: adspace in $data --><tr ng-repeat="adspace in $data" ng-click="changeSelection(adspace, selectedAdspace.$edit)" ng-class="{'active': adspace.$selected}" class="ng-scope">
<td id="TabCode" data-title="translate('win-web-adspace.lbl-code')" class="col-sm-2 ellipsing ng-binding" sortable="'code'" data-title-text=" ">ADSPACE2</td>
<td data-title="translate('win-web-adspace.lbl-name')" class="col-sm-3 ellipsing ng-binding" sortable="'name'" data-title-text=" ">Ad Space 2</td>
<td data-title="translate('win-web-adspace.lbl-desc')" class="col-sm-3 ellipsing ng-binding" sortable="'desc'" data-title-text=" ">Ad Space 2</td>
<td ng-show="expiredFilter == 2" data-title="translate('global.lbl-expired')" class="col-sm-2 ng-hide" sortable="'expired'" data-title-text=" ">
<input type="checkbox" ng-model="adspace.adspaceExpired" ng-true-value="true" ng-false-value="false" ng-disabled="true" ng-checked="adspace.adspaceExpired" class="ng-pristine ng-valid" disabled="disabled">
</td>
<td class="col-sm-2 nowrap" data-title-text=" ">
<!-- ngIf: !selectedAdspace.$edit --><a ng-if="!selectedAdspace.$edit" class="row-icon ng-scope">
<i class="fa fa-lg fa-pencil-square-o cursor-pointer"></i>
</a><!-- end ngIf: !selectedAdspace.$edit -->
<!-- ngIf: !selectedAdspace.$edit && !adspace.expired --><!-- cawAuth: hasRole('ROLE_MC_ADM_OL_ADSPACE_D') --><a ng-really-click="deleteAdspace(adspace);" ng-really-message="This action cannot be undone. Are you sure you want to delete this?" ng-if="!selectedAdspace.$edit && !adspace.expired" class="row-icon ng-scope ng-isolate-scope" caw-auth="hasRole('ROLE_MC_ADM_OL_ADSPACE_D')">
<i class="fa fa-lg fa-times cursor-pointer"></i>
</a><!-- end cawAuth: hasRole('ROLE_MC_ADM_OL_ADSPACE_D') --><!-- end ngIf: !selectedAdspace.$edit && !adspace.expired -->
</td>
</tr><!-- end ngRepeat: adspace in $data -->
</tbody></table>
&#13;
//The thisAdspaceNumb = ADSPACE2;
var thisAdspaceNumb = "";
var nextAdspaceNumb;
thisAdspaceNumb = element.all(by.id('TabCode')).last().getText();//.toString().substring(7,10);
for(var i = 0;i < 10;i++)
{
var tmp = "ADSPACE" +i;
if(thisAdspaceNumb == tmp)
{
nextAdspaceNumb = "ADSPACE" + (i + 1);
break;
}
}
element(by.id("code")).sendKeys(nextAdspaceNumb);`
答案 0 :(得分:0)
在thisAdspaceNumb
中,getText()
会返回一个Promise,因此您需要像以下一样使用它:
element.all(by.id('TabCode')).last().getText().then(function(text) {
var thisNumber = parseInt(/(\d+)/.exec(text)[1]);
return thisNumber + 1;
}).then(function(nextNumber) {
element(by.id('code')).sendKeys(nextNumber);
});