2012-04-12 313 views
1

我的页面上有画布元素,我想单击它的某个部分。 我知道,我必须用ActionBuilder要做到这一点,所以我tryed验证码:Webdriver。点击坐标上的Canvas元素

element = driver.find_element(:xpath, canvas_xpath) 
action.move_to(element, 100, 100).click.perform 

但这代码只在canvas元素的中心单击,不以任何方式移动鼠标。

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

回答

1

你试过action.move_to(element).move_by(100, 100).click.perform

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. 
    # 

根据这一点,我的结论,应该只是在两条线等执行这些操作:

element = driver.find_element(:xpath, canvas_xpath) 
driver.action.move_to(element, 100, 100).perform 
driver.action.click.perform 

element = driver.find_element(:xpath, canvas_xpath) 
driver.action.move_to(element).perform 
driver.action.move_by(100, 100).click.perform 

可悲的是,这一切都没有效果(对我来说IE):(

+0

我解决我的问题在偏远的IE浏览器这样的: '硒:: ::的webdriver远程::功能:: internet_explorer(: javascript_enabled => true,:native_events => true)' – murtabak 2013-01-15 12:13:56