量角器 E2E:从 getText() 方法获取第一个值?

Protractor E2E : get first value from getText() method?

我有一个由中继器选择的元素选择器。 我得到

6
Cost

来自

element.getText().then(function (balance) {
          console.log(balance);
        });

我只需要挑$186,我试过用first();的元素得到的。 和平衡[0]。但没有找到解决方案。 请建议。

如果元素存在于 DOM 中,如下所示:

<span ng-repeat="record in records">6</span><span ng-repeat="record in records">Cost</span>

然后下面的代码有效:

element.all(by.repeater('record in records')).get(0).getText().then(function(txt) {
    console.log('txt:'+txt);
});

从字符串中的元素存储中获取文本后。 根据您所知道的模式找到所需的子字符串。

var res = str.substring(0, 4);//Change as per the pattern or use regex if required.