xpath - 使用 cssSelector 获取子元素

标签 xpath css-selectors protractor cucumberjs

我有一个看起来像这样的代码段

<div class="class1">
    <div class="ng-scope"> apple </div>
    <div class="ng-scope"> butter </div>

我想得到 children 的文字。我不想使用 ng-scope,因为它不是唯一标识符,但 class1 是。我怎样才能做一些事情,比如识别 parent ,所以('.class1')或使用xpath,然后从它的所有 child 那里获取文本。所以打印出来的东西看起来像
" [ apple, butter ]; "

最佳答案

$$('.class1 div').getText().then(function(values) {
  // This is an array containing ['apple', 'butter']
});

关于xpath - 使用 cssSelector 获取子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40850668/

相关文章:

html - 如何在不调用 "next_element"方法的情况下使用 Nokogiri 选择下一个元素?

xml - 在 Google 表格中使用 ImportXML 的 <address> 标记的 XPath

c# - Java XML XPath 解析器到 C#

node.js - 获取范围错误 : Maximum call stack size exceeded on Protractor Typescript Automation Framework

selenium - 使用 Bamboo CI 设置 Protractor e2e 测试

xml - 有什么作用! XPath 3.0 中的意思是什么?

css - 在表 tr td 中使用第 n 个 child

jquery - 在表中查找 <tr>

jquery - Css 选择器 - 选择所有同级直到某个同级

javascript - 我们应该用什么来代替 Selenium 中的 getInnerHtml() 和 getOutterHtml()?