元素内的 Capybara Scope 以创建 href 数组

Capybara Scope within element to create array of href

我正在编写测试,将在包含 4 个 href 的元素中查找,并在其中创建每个 href 的数组,然后依次单击每个 href 并期待结果。

查看 Capybara DSL 文档,我看不到一种确定范围的方法,然后调用所有方法,有点像这样:

links = all(:href).within('id-of-element')

我只想保留它 all(:href) 但有 3 个元素包含 4 个 href,我需要具体说明我正在与之交互的元素。

有办法吗?

Capybaras 会占用一个块并在会话中调用,它不是您可以在节点或 "array" 个节点上调用的方法

within("#id") do
  find(...) # result scoped to inside element with id
end

您的另一种选择是仅在一个节点上调用 find/first/all 并将其范围限定为该节点

find("#id").all(...). # results of all are scoped to element with id