1 回答
TA贡献1891条经验 获得超3个赞
元素.所有应该工作正常
HTML View
<div id='id1' class="parent">
<ul>
<li class="foo">1a</li>
<li class="baz">1b</li>
</ul>
</div>
<div id='id2' class="parent">
<ul>
<li class="foo">2a</li>
<li class="bar">2b</li>
</ul>
</div>
Code
let foo = element.all(by.css('.parent')).all(by.css('.foo'));
expect(foo.getText()).toEqual(['1a', '2a']);
let baz = element.all(by.css('.parent')).all(by.css('.baz'));
expect(baz.getText()).toEqual(['1b']);
let nonexistent = element.all(by.css('.parent'))
.all(by.css('.NONEXISTENT'));
expect(nonexistent.getText()).toEqual(['']);
// Or using the shortcut $$() notation instead of element.all(by.css()):
let foo = $$('.parent').$$('.foo');
expect(foo.getText()).toEqual(['1a', '2a']);
let baz = $$('.parent').$$('.baz');
expect(baz.getText()).toEqual(['1b']);
let nonexistent = $$('.parent').$$('.NONEXISTENT');
expect(nonexistent.getText()).toEqual(['']);
element.all 返回一个 promise 数组。您可以迭代数组和链接以查找位于输入标记后面的标签。
添加回答
举报