Selenium 2:moveByOffset()和连续release() - 奇怪的定位

时间:2012-03-16 10:36:24

标签: selenium selenium-webdriver

我在FirefoxDriver中使用Selenium 2。任务是移动几个像素的元素。我用这种方式编写任务:

val action = (new Actions(driver)).clickAndHold(el).moveByOffset(3,1).release().perform()

记录mouseDown(),mouseMove()和mouseUp()事件。所以我收到以下输出:

mouseDown at 267 133
mouseMove at 270 134
mouseMove at 267 133
mouseUp at 267 133

看起来Selenium会在项目上调用mouseDown,然后将其移动到指定位置,然后将其移回,然后调用mouseUp。这很奇怪。

事实证明,原因是在release()调用中,因为我称之为:

val action = (new Actions(driver)).clickAndHold(el).moveByOffset(3,1).perform()

我明白了:

mouseDown at 267 133
mouseMove at 270 134

如何让Selenium在正确的位置调用mouseUp?

1 个答案:

答案 0 :(得分:2)

听起来像个错误......可能的解决方法是:

val action =(new Actions(driver))。dragAndDropToOffset(el,el.Location.X + 3,el.Location.Y + 1).perform()