水豚点击方法传参导致not a key modifier错误

Capybara click method passing parameters results in not a key modifier error

我正在尝试使用具有 Rdoc 中定义的偏移量的 Capybara Node::Element 单击。

基本上,我想在元素上使用点击方法,但不是点击元素的中心,而是向左偏移。我不想使用 action.move_to 方法。

#click(*key_modifiers = [], offset = {x: nil, y: nil}) ⇒ Capybara::Node::Element
Click the Element

Parameters:

*key_modifiers (Array<:alt, :control, :meta, :shift>) (defaults to: []) 
— Keys to be held down when clicking
  offset (Hash) (defaults to: {x: nil, y: nil}) — x and y coordinates 
  to offset the click location from the top left corner of the element. 
  If not specified will click the middle of the element.

如果我想要默认的 key_modifier ('[ ]'),我只是不确定如何使用它。当我尝试这个时,我得到一个不是键修饰符的错误。

elem = find(some_xpath)
elem.click([], {x: -20, y: nil})

 ArgumentError:
 [] is not a modifier key, expected one of [:control, :shift, :alt, 
 :command, :meta]

我试过跳过 [] 但它似乎没有执行偏移

elem.click({x: -100 y:nil})

您需要同时指定 x 和 y,不能为其中一个指定 nil

click(x: -100, y: 0)