问题描述
我在我的页面上有一个canvas元素,我想点击这个画布中的特定(x,y)坐标。我使用watir-webdriver:
I have a canvas element on my page and I want to click on specific (x, y) coordinates in this canvas. I use watir-webdriver:
element = browser.driver.find_element(:id, 'canvas')
browser.driver.action.move_to(element).move_by(x, y).click().perform
但是这段代码只是点击画布的中心,而不是指定的(x,y)坐标。是什么问题?
But this code just clicks on the center of the canvas, not the specified (x, y) coordinates. What is wrong with it?
UPD:
现在我使用这个代码:
UPD:So now I use this code:
element = browser.driver.find_element(:id, 'canvas')
browser.driver.action.move_to(element, x, y).perform
browser.driver.click.perform
但它仍然点击画布的中心,而不是指定的y)坐标...任何想法?
But it still clicks on the center of the canvas and not on specified (x, y) coordinates... Any thoughts?
UPD 2:这只是FIREFOX问题(在Chrome中运行良好)
UPD 2: This is only the FIREFOX issue (works well in Chrome)
推荐答案
移动
move_to(element)
指定的元素的中心, move_by
是一个相对移动。所以通过这两个操作的结束,你已经移动到坐标(元素中心+ x的x,元素中心+ y的y)
。
Movement
move_to(element)
moves to the center of the element specified and move_by
is a relative move. So by the end of these two operations, you have moved to the coordinates (x of element center + x, y of element center + y)
.
您应该使用 move_to(element,x,y)
。这将移动到相对于元素原点的 x,y
坐标。
You should use move_to(element, x, y)
. This will move to the x, y
coordinates relative to the origin of the element.
相关。
您使用的是Selenium和Firefox的版本,而Selenium支持本地事件? Selenium 2.37与Firefox 24的组合。我有测试套件失败,因为本机事件不可用。
Are you using a version of Selenium and Firefox for which Selenium supports native events? The combination of Selenium 2.37 with Firefox 24 does. I've had test suite fails just because native events were not available.
这篇关于如何点击canvas中的特定元素的坐标(使用WebDriver)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!