量角器无法访问其 class 共享其他元素的特定元素

Protractor Unable to access a specific element that has its class shared other elements

我正在尝试访问特定元素,但该元素名称与同一页面中的其他元素一起使用

这是html

<div class="details of buyer">
  <div class="field">
  <small>Balance</small>
  <div>5000</div>
  </div>
  <div class="field">
  <small>Lodgements</small>
  <div>108,000.00</div>
  </div>
  <div class="field">
  <small>Max Withdrawal</small>
  <div>107,561.00</div>
  </div>
  <div class="field">
  <small>Credits</small>
  <div>-</div>
  </div>
  <div class="field">
  <small>Interest Rate</small>
  <div>-</div>
  </div>
  <div class="field">
  <small>Net Gain</small>
  <div>-</div>
  </div>
  <div class="field">
  <small>Net Yield</small>
  <div>-</div>
  </div>
 </div>
我正在尝试从以下内容中检索“107,561.00” <small>Max Withdrawal</small> <div>107,561.00</div>

我已经在我的页面目标文件中试过了,但是它 returns "Index Out of Bound"... var checkBalance= element.all(by.css('div.field> small> div')).get(2);

感谢您的帮助

你应该得到它:

$$('div.field div').get(2);

我为我的 Protractor 代码使用自定义 selectors,它更可持续:

  <div class="field">
    <small data-custom-selector="max-withdrawal-text">Max Withdrawal</small>
    <div data-custom-selector="max-widthdrawal-amount">107,561.00</div>
  </div>

  var checkBalance = element(by.css('[data-custom-selector="max-widthdrawal-amount"]'));

您可以将 data-custom-select 或 命名为任意名称,只要保留 data-部分,其他例子:data-test-select, data-test-ptr