的webdriver.按坐标单击Canvas元素

Sho*_*eNN 1 ruby selenium canvas webdriver

我的页面上有canvas元素,我想点击它的某些部分.我知道,我必须使用ActionBuilder来做到这一点,所以我尝试了这段代码:

element = driver.find_element(:xpath, canvas_xpath)
action.move_to(element, 100, 100).click.perform
Run Code Online (Sandbox Code Playgroud)

但是这段代码只点击画布元素的中心,不以任何方式移动鼠标.

有没有其他可能的方法将鼠标移动到某些坐标?(不要提到AutoIT脚本 - 我在Linux下开发)

小智 6

我在IE中遇到同样的问题.ShockwaveNN的代码适用于Firefox和Chrome.我认为问题是在元素中间点击"点击".以下是action_builder.rb中的文档:

  #
  # Clicks in the middle of the given element. Equivalent to:
  #
  #   driver.action.move_to(element).click
  #
  # When no element is passed, the current mouse position will be clicked.
  #
  # @example Clicking on an element
  #
  #    el = driver.find_element(:id, "some_id")
  #    driver.action.click(el).perform
  #
  # @example Clicking at the current mouse position
  #
  #    driver.action.click.perform
  #
  # @param [Selenium::WebDriver::Element] element An optional element to click.
  # @return [ActionBuilder] A self reference.
  #
Run Code Online (Sandbox Code Playgroud)

根据这个和我的结论,它应该只是在两行中执行这些操作,如:

element = driver.find_element(:xpath, canvas_xpath)
driver.action.move_to(element, 100, 100).perform
driver.action.click.perform
Run Code Online (Sandbox Code Playgroud)

要么

element = driver.find_element(:xpath, canvas_xpath)
driver.action.move_to(element).perform
driver.action.move_by(100, 100).click.perform
Run Code Online (Sandbox Code Playgroud)

可悲的是,这一切都不起作用(对我来说在IE中):(