【问题标题】:Python windows app UI automation testing: how to send mouse and keyboard events to winappdriver?Python windows app UI自动化测试:如何向winappdriver发送鼠标和键盘事件?
【发布时间】:2019-01-09 02:27:58
【问题描述】:

我正在测试一个窗口应用程序(窗口窗体)。我使用python(appium,robotframework),winAppDriver。

我的任务:

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

我需要做什么:

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

我已经找到了元素。但我浏览了文档,仍然无法找出如何在 python 中执行此操作。

是否可以通过:

  • 将帖子发送到 url 127.0.0.1:4723/:sessionId/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')

【问题讨论】:

    标签: python winforms appium ui-automation winappdriver


    【解决方案1】:

    您可以使用 driver.send_keys(Keys.SHIFT + Keys.F10) (键盘上的 Shift+F10 是右键单击的快捷方式)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 1970-01-01
      • 2014-10-04
      • 2023-03-05
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多