5

別の要素の後に要素を取得することは可能ですか? (サブエレメントではない)

HTML コード:

<input id="first-input" type="text"/>
<ul>
    <li>1</li>
    <li>2</li>
</ul>
<input id="second-input" type="text"/>
<ul>
    <li>1</li>
    <li>2</li>
</ul>
<input id="third-input" type="text"/>
<ul>
    <li>1</li>
    <li>2</li>
</ul>

どうすればul次のものを入手できますelement(by.id('second-input'))か?

これが私の理解です:

element(by.id('second-input')).element(by.tagName('ul')) // This doesn't work because this looks for sub-elements in <input id="second-input">
element.all(by.tagName('ul')).first() // This doesn't work because it gets the 'ul' following <input id="first-input">
element(by.id('second-input')).element.all(by.tagName('ul')) // This doesn't work because this looks for all 'ul' elements as sub-elements of <input id="second-input">

私の場合、これらの「ul」には一意の ID や一意のものはありません。

4

2 に答える 2

10

次の兄弟を使用by.xpath()して求めることができます。ul

element(by.id('second-input')).element(by.xpath('following-sibling::ul'));

または、一度に:

element(by.xpath('//input[@id="second-input"]/following-sibling::ul'));

別のオプションはby.css()隣接する兄弟セレクターで使用することです。

element(by.css('#second-input + ul'));
于 2015-01-07T06:42:44.970 に答える