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



我有由中继器选择的元素选择器。我正在得到

$186
Cost

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

我只需要选择 186 美元,我试图通过使用first();元素来获得。和余额[0]。但没有找到解决方案。请指教。

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

<span ng-repeat="record in records">$186</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.

最新更新