提问者:小点点

Pythonwindows应用程序UI自动化测试:如何发送鼠标和键盘事件到winapp驱动程序?


我正在测试一个窗口应用程序(窗口表单)。我使用python(appium、robotframe)、winAppDriver。

我的任务:

  • 右键单击一个按钮,显示上下文菜单,然后选择其中一个。

我需要做什么:

  • 使用python发出右键,然后选择菜单动作(就像selenium web中的动作链)

我已经找到了元素。但是我浏览了文档,仍然没有找到如何在python中做到这一点。

是否可以通过:

  • 发送帖子到url127.0.0.1:4723/: session sionId/Buttondown.
  • 使用python将密钥发送到Web元素位置?(我设法在我的代码中做到了这一点,但这不是我想要的,代码看起来很丑)

我的简短代码:

#to test a window application, wrote by C# windows form
from appium import webdriver

desired_caps = {}
desired_caps["app"] = "D:\\sample.exe"
driver =webdriver.Remote(command_executor='http://127.0.0.1:4723',desired_capabilities=desired_caps)
button= driver.find_element_by_name("Root")

#button.contextClick()??
#how to 

#I managed to use pyautogui, to send mouse and keyboard event, but the code look ugly. FYI.
driver_location=driver.get_window_position()
root=driver.find_element_by_name("Root")
root.click()
button_location=root.location

x, y = pyautogui.position()
pyautogui.moveTo(button_location['x']+driver_location['x'],button_location['y']+driver_location['y'])
pyautogui.click( button='right')

共1个答案

匿名用户

您可以使用驱动程序。send_keys(Keys. SHIFT Keys.F10)(从键盘移位F10是右键单击的快捷方式)。