我正在使用selenium2library进行拖放操作的自动化测试.我在windows 8 64bit,selenium 2.48.0,ride.py上运行.用于测试的浏览器:firefox和chrome最新稳定版
我所做的是创建一个带有输入文本和链接的虚拟html页面,然后尝试将该链接拖动到输入文本中
这是html:
<div id="wrapper">
<input id="target" type="text" style="width:200px; height:50px" />
</div>
<a id="source" href="http://google.com" >drag me </a>
Run Code Online (Sandbox Code Playgroud)
这是我的自动化python代码:
class CustomSeleniumLibrary(Selenium2Library):
...
def test_drag(self):
self.open_browser("http://localhost:8080/a.html", "firefox")
source = self._element_find("//a[@id='source']", True, True)
target = self._element_find("//input[@id='target']", True, True)
drag = ActionChains(self._current_browser()).click_and_hold(source)
moveDum = ActionChains(self._current_browser()).move_by_offset(1,1)
move = ActionChains(self._current_browser()).move_to_element_with_offset(target,1,1)
#I have also tried ActionChains().drag_and_drop().perform() or make a dummy move move_by_offset followed by move_to_element_with_offset but no use
drag.perform()
moveDum.perform()
move.perform()
Run Code Online (Sandbox Code Playgroud)
我发现当移动完成或mouse_down()完成时,下一个动作没有执行,我可以看到链接被保持,但是直到我在浏览器上手动移动鼠标才执行移动操作.ride.py UI当时的电影和请求:
16:24:47.042 : DEBUG : POST http://127.0.0.1:58095/hub/session/fa7590b6-396f-4cb5-a08a-e35138a9216e/moveto {"sessionId": "fa7590b6-396f-4cb5-a08a-e35138a9216e", "element": "{6586b4ae-3c51-4e18-bb40-e006af369768}", "xoffset": 1, "yoffset": 1}
永远挂起,直到我在浏览器上手动移动鼠标
你们中的任何人都有同样的问题,或者我做错了什么?你对使用机器人框架selenium2library使用拖放功能有什么建议吗?
最好的问候,丹
我无法检查它,但据我记得是ActionChains这样工作的:
actions = ActionChains(self._current_browser())
actions.click_and_hold(source)
actions.move_by_offset(1,1)
actions.move_to_element_with_offset(target,1,1)
actions.perform()
Run Code Online (Sandbox Code Playgroud)
如果此代码工作不正确,请告诉我