【发布时间】:2018-03-30 05:00:38
【问题描述】:
我是守夜人的新手,想知道是否有什么好的方法可以选择当前元素的内部元素然后获取文本?假设我有以下内容..并且我正在尝试检索每个 (li) 的 (a) 标签内的文本。
所以我想获取“要检索的文本”和“要检索的文本 2”。
...
<div class="mywrapperhere">
<ul>
<li>
<a>.....
<div>text to retrieve</div>
</a>
</li>
<li>
<a>.....
<div>text to retrieve 2</div>
</a>
</li>
<li>...
...
</div>
我是这么想的..
module.exports = {
'Demo test 1' : function (browser) {
....
//some sort of selector then gets from the anchor list
...'.mywrapperhere li a') : {
..
//for each element of the anchor..
{
//is there anyway to get it through something like
element.('div').innerHTML eg..
//or am i forced to use browser.execute( ...getElementsByTag method
//to achieve this?
}
}
browser.end();
}
};
查看 nightwatch api,我找不到任何允许我这样做的东西。我特别关注“元素状态”示例,这些示例似乎无法让我选择当前元素状态的子元素:
http://nightwatchjs.org/api/elementIdAttribute.html
我必须遍历锚标记级别的原因是因为除了来自 div 标记的数据之外,我还需要检索更多数据,谢谢!
【问题讨论】:
标签: nightwatch.js