【问题标题】:CodeceptJS how to return an array of elements? - similarly to querySelectorAllCodeceptJS如何返回一个元素数组? - 类似于 querySelectorAll
【发布时间】:2021-08-31 00:54:11
【问题描述】:

在控制台中编写以下命令:

document.querySelectorAll("[type='checkbox']")

返回:

NodeList(12) [input.jss719, input.jss719, input.jss719, input.jss719, input.jss719, input.jss719, input.jss719, input.jss719, input.jss719, input.jss719, input.jss719, input.jss719]

这正是我想在 Codeceptjs 中实现的,所以我可以稍后循环遍历元素。

我尝试过创建自定义函数,例如:

 allSelector: function (selector)  {
  return Array.from.document.querySelectorAll(selector)
}

但是,我在控制台记录时不断收到null

  let checkboxes =  (await I.grabAttributeFrom("[type='checkbox']"))

  console.log(checkboxes)

【问题讨论】:

    标签: javascript automation codeceptjs


    【解决方案1】:

    需要指定属性名,例如'name'

    let checkboxes =  (await I.grabAttributeFrom("[type='checkbox']", "name"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-21
      • 2016-12-30
      • 2019-01-25
      • 2020-03-09
      • 1970-01-01
      • 2018-12-25
      相关资源
      最近更新 更多