我正在为应用程序自动化UI测试,并且在Windows上的菜单项遇到了麻烦。 Fwiw,我在Mac上为姐妹应用程序工作。 我正在从Python使用Appium。
我可以使用Inspect.exe查找菜单树,单击顶级菜单,然后打开下拉菜单,在这里我找到要单击的菜单项,但是WinAppDriver失败,并出现以下错误:
{"status":105,"value":{"error":"element not interactable","message":"An element command could not be completed because the element is not pointer- or keyboard interactable."}}
下面的python重现了问题。
import time
import unittest
from appium import webdriver
app_exe_path = "C:\\Program Files\\Phase One\\Capture One 12\\CaptureOne.exe"
menu_name = "Select"
menu_item_name = "First"
switch_window = True
# app_exe_path = "C:\\Windows\\Notepad.exe"
# menu_name = "File"
# menu_item_name = "Open..."
# switch_window = False
class ClickApplicationMenuItem(unittest.TestCase):
def test_click_application_menu_item(self):
driver = webdriver.Remote(
command_executor="http://localhost:4723",
desired_capabilities={"app": app_exe_path},
)
if switch_window:
time.sleep(5) # non-optimal code for the sake of a simple repro
handles = driver.window_handles
driver.switch_to.window(handles[0])
menu = driver.find_element_by_name(menu_name)
menu.click() # fails in the Notepad case
item = menu.find_element_by_name(menu_item_name)
item.click() # fails in the CaptureOne case
if __name__ == "__main__":
unittest.main()
关于如何单击菜单项的任何建议?
答案 0 :(得分:1)
这是菜单项的最终结果(我保留Attr("templateGid ").eq(12345666) & Attr("updatedAt").gt("2019-11-01T00:00:00.000Z") & Attr("name ").eq("foo")
,因为它对应用程序有效,正在测试):
menu.click()
答案 1 :(得分:0)
由于您能够找到这些元素,因此我假设您有权访问它们的属性。 一个简单的解决方法是单击元素坐标,而不是单击元素本身。通常,单击坐标不是一个好主意,但是由于您是从元素本身获取坐标的,所以我在这里没有问题。
尝试这样的事情:
menu = driver.find_element_by_name(menu_name)
driver.Mouse.Click(menu.coordinates)
item = menu.find_element_by_name(menu_item_name)
driver.Mouse.Click(item.coordinates)
我确实收到警告,说明鼠标功能已过时,应使用Actions
或ActionBuilder
类。您也可以探索这些选项,但我发现该问题已于2018年3月在winappdriver的github页上关闭,涉及到Actions
类。目前尚不清楚为什么关闭。您可以找到另一种单击坐标的方式。
资源:
Actions
issue