我在 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 中对我来说):(