Angularjs 量角器:我怎样才能得到下一个标签
有可能一个元素接一个元素吗?(不是子元素) HTML代码:Angularjs 量角器:我怎样才能得到下一个标签,angularjs,testing,jasmine,protractor,end-to-end,Angularjs,Testing,Jasmine,Protractor,End To End,有可能一个元素接一个元素吗?(不是子元素) 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&
<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”没有唯一的ID或任何唯一的东西。您可以使用并请求以下ul
同级:
或者,一次性:
element(by.xpath('//input[@id="second-input"]/following-sibling::ul'));
另一种选择是与以下设备一起使用:
使用Xpath选择器不是更好的选择,因为它会减慢元素查找机制 这将是非常简单的插件。此插件将帮助您使用css选择器查找同级元素 使用下载插件
npm install --save protractor-css-booster
在配置文件中添加插件:
exports.config = {
// ... the rest of your config
plugins: [
{
// The module name
package: "protractor-css-booster"
}
]
};
现在,您可以找到如下元素:
const ulElem=element(by.css('#second-input')).element(by.followingSibling('ul')); \\ returns the first div
为uls提供唯一ID。由于它不是嵌套的,javascript将无法理解您的函数ULs是由第三方库生成的。我不想碰它。还有其他选择吗?
npm install --save protractor-css-booster
exports.config = {
// ... the rest of your config
plugins: [
{
// The module name
package: "protractor-css-booster"
}
]
};
const ulElem=element(by.css('#second-input')).element(by.followingSibling('ul')); \\ returns the first div