硒转移到绝对位置

时间:2015-04-07 10:05:34

标签: python html selenium

我使用python包以某种指定模式或随机运动移动鼠标。

我尝试的第一件事是获取//html元素的大小,并使用它来制作鼠标移动的边界。但是,当我这样做时,MoveTargetOutOfBoundsException会抬起头来显示一些"给出"坐标(不在输入附近。

我使用的代码: origin = driver.find_element_by_xpath('//html') bounds = origin.size print bounds ActionChains(driver).move_to_element(origin).move_by_offset(bounds['width'] - 10, bounds['height'] - 10).perform()

所以我从每个边界中减去10来测试它并移动到那个位置(显然move_to_element_by_offset方法是狡猾的)。

MoveTargetOutOfBoundsException: Message: Given coordinates (1919, 2766) are outside the document. Error: MoveTargetOutOfBoundsError: The target scroll location (17, 1798) is not on the page. Stacktrace: at FirefoxDriver.prototype.mouseMoveTo (file://...

实际给定的坐标是(1903-10=1893, 969-10=989)。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

两个可能的问题:

1)页面上可以滚动,所以在点击之前你应该滚动到元素视图

2)尺寸是在没有浏览器元素尊重的情况下给出的,在现实世界中你应该用20或30代替原始尺寸(你可以测试那些值)

答案 1 :(得分:0)

我的问题是我没有等待元素加载。至少我认为问题是什么,因为如果我允许selenium等待元素然后点击它,它就可以了。

相关问题