import clr
clr.AddReference("UIAutomationClient")
clr.AddReference("UIAutomationTypes")
from System.Windows.Automation import *
# 找到窗口标题
dialogTitle = "Dialog Title"
windowElement = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.NameProperty, dialogTitle))
# 找到窗口中的元素
element = windowElement.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit))
# 操作元素
element.SetFocus()
element.SetValue("input value")
首先需要安装AutoIt库,然后在Appium中调用AutoIt函数来处理。
import autoit
dialogTitle = "Dialog Title"
# 使用AutoIt查找窗口句柄
autoit.win_wait(dialogTitle)
hwnd = autoit.win_get_handle(dialogTitle)
# 设置窗口输入框的值
autoit.control_send(hwnd, "", "[CLASS:Edit; INSTANCE:1]", "input value")