我正在尝试访问特定元素,但元素名称在同一页面中的其他元素中使用
这是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>
<small>Max Withdrawal</small>
<div>107,561.00</div>
我在我的页面对象文件中尝试了这个但它返回“Index Out of Bound”....
var checkBalance= element.all(by.css('div.field> small> div')).get(2);
感谢您的帮助
答案 0 :(得分:1)
你应该得到它:
$$('div.field div').get(2);
答案 1 :(得分:0)
我在我的Protractor代码中使用自定义选择器,它更具可持续性:
<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-test-select , data-test-ptr