水豚单击方法传递参数不会导致键修改器错误

时间:2018-11-19 18:19:11

标签: selenium-webdriver capybara

我正在尝试使用“水豚节点” :: Element单击Rdoc中定义的偏移量。

基本上,我想在元素上使用click方法,但不要在元素的中心单击NOT,而是向左偏移。我不想执行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})

1 个答案:

答案 0 :(得分:1)

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

click(x: -100, y: 0)