首页 > 解决方案 > Squish moveMouse 返回错误:移动鼠标失败

问题描述

我正在使用 Squish 6.3.0 Beta 版来测试用 Qt 编写的应用程序(我知道有更新的版本,但目前无法进行升级)。我正在尝试移动鼠标以获取工具提示,但 mouseMove 命令返回 RuntimeError: Failed to move the mouse。包装器函数是python中的编写器代码heretten:

def mouse_move(self, object_name, x, y, timeout=None):
try:
    my_obj = waitForObject(object_name, timeout)
    logging.debug("Found object: {0}".format(my_obj.objectName))
    mouseMove(my_obj, x, y)
    logging.debug("Mouse moved to: {object_name}".format(object_name=my_obj.objectName))
except Exception, e:
    logging.error("Error: {0}".format(e))
    ex_type, ex_value, ex_traceback = sys.exc_info()
    trace_back = traceback.extract_tb(ex_traceback)
    stack_trace = list()
    for trace in trace_back:
        stack_trace.append(
                "File : %s , Line : %d, Func.Name : %s, Message : %s" % (trace[0], trace[1], trace[2], trace[3]))
    logging.error("Exception type: {0}".format(ex_type.__name__))
    logging.error("Exception message: {0}".format(ex_value))
    logging.error("Stack trace: {0}".format(stack_trace))

我得到的输出:

16:19:11 DEBUG:    Found object: name_of_the_object
16:19:11 ERROR:    Error: Failed to move the mouse
16:19:11 ERROR:    Exception type: RuntimeError
16:19:11 ERROR:    Exception message: Failed to move the mouse
16:19:11 ERROR:    Stack trace: path/my_squish_wrapper.py , Line : 170, Func.Name : mouse_move, Message : mouseMove(my_obj, x, y)']

有谁知道为什么鼠标不能移动?或者我应该检查什么以获得更多信息。

标签: squish

解决方案


如果有人需要,我已经找到了解决此 mouseMove 问题的方法:

        rect = object.globalBounds(my_obj)
        x = rect.center().x
        y = rect.center().y
        QCursor.setPos(x, y)

推荐阅读