如何获得ProtractorJS上最后一个元素的第n个

pat*_*atz 1 jasmine angularjs protractor

这就是我所拥有的:

<input type=text class='someclass'> box1 </input>
<input type=text class='someclass'> box2 </input>
<input type=text class='someclass'> box3 </input>
Run Code Online (Sandbox Code Playgroud)

我想在getAttribute('value')文本框2中使用last()ProtractorJS中的函数(意味着最后一个元素的第n个).

describe('get input box value',function(){
    it('get value', function(){
       expect(element.all(by.className('someclass')).last().getAttribute('value').toBe('box2'));
    });
});
Run Code Online (Sandbox Code Playgroud)

我不能使用这个get()功能,get(1).getAttribute('value')因为我的要求是特定的,这对我不起作用.

有没有人知道如何获得ProtractorJS中最后一个元素的第n个?

han*_*uan 9

get应该是你所需要的一切.它可以采用负数索引-n表示从最后一个开始计算的第n个元素.见http://angular.github.io/protractor/#/api?view=ElementArrayFinder.prototype.get

即说你有10个元素:['a','b',...,'i','j']

$$('abc').get(0) -> 'a'
$$('abc').get(1) -> 'b'
$$('abc').get(-1) -> 'j'
$$('abc').get(-2) -> 'i'
$$('abc').get(-10) -> 'a'
Run Code Online (Sandbox Code Playgroud)