1

我正忙于应用程序的 UI 自动化,在该应用程序中,可以制作与 Paint 应用程序相当的样式的绘图。在被测应用程序中,这个区域是通过一个画布元素创建的。

我的目标是通过 Selenium 和机器人框架在此画布上进行一种绘图,例如画一条线:

  1. 鼠标按下某个位置
  2. 鼠标移动到新位置
  3. 在新位置释放鼠标

在机器人框架的 Selenium2Library 的官方文档中,我看到没有适合我需要的关键字(关键字“单击坐标处的元素”不起作用)。但是,通过搜索我发现有一个关键字“mouse_down_at”,但在标准机器人框架中无法访问该关键字。但是,关键字“mouse_down_at”存在于 Selenium 文件夹(Python 站点包)中的 selenium.py 文件中。

现在,我正在寻找一种在机器人框架中访问此关键字“mouse_down_at”的方法。我已经尝试自己编写一个包装库,但到目前为止还没有成功。

4

1 回答 1

4

您可以创建自己的 Selenium2Library 版本并使用它来代替标准的 Selenium2Lib。像这样的东西:

from Selenium2Library import Selenium2Library
from selenium.webdriver.common.action_chains import ActionChains

class Selenium2Improved(Selenium2Library):
    '''Sometimes Selenium2Library just dont go far enough.'''

    def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Capture Page Screenshot'):
        super(Selenium2Improved, self).__init__()

    def mouse_down_at(self, locator, coordx, coordy):
        element = self._element_find(locator, True, False)
        if element is None:
            raise AssertionError("ERROR: Element %s not found." % (locator))
        ActionChains(self._current_browser()).move_to_element(element).move_by_offset(coordx, coordy).click_and_hold().perform()

    def mouse_up_at(self, locator, coordx, coordy):
        element = self._element_find(locator, True, False)
        if element is None:
            raise AssertionError("ERROR: Element %s not found." % (locator))
        ActionChains(self._current_browser()).move_to_element(element).move_by_offset(coordx, coordy).release().perform()
于 2013-11-12T06:42:30.590 回答