Jas*_*son 5 testing end-to-end jasmine angularjs protractor
是否有可能在另一个元素之后得到一个元素?(不是子元素)
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>
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到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">
Run Code Online (Sandbox Code Playgroud)
就我而言,这些'ul'没有独特的ID,或者任何独特的东西.
您可以使用by.xpath()并要求以下ul兄弟:
element(by.id('second-input')).element(by.xpath('following-sibling::ul'));
Run Code Online (Sandbox Code Playgroud)
或者,一气呵成:
element(by.xpath('//input[@id="second-input"]/following-sibling::ul'));
Run Code Online (Sandbox Code Playgroud)
element(by.css('#second-input + ul'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4107 次 |
| 最近记录: |