C# UIC文本框随着鼠标单击或失去焦点而消失
iam在visual c express 2010中使用UIAutomation 我试图在UI applicton中自动输入文本框,我成功地选择了需要输入数据的窗口,但如果我切换窗口或更改聚焦字段,输入数据后会发生什么?文本突然消失这里是我处理的字段的UIspy日志C# UIC文本框随着鼠标单击或失去焦点而消失,c#,ui-automation,microsoft-ui-automation,C#,Ui Automation,Microsoft Ui Automation,iam在visual c express 2010中使用UIAutomation 我试图在UI applicton中自动输入文本框,我成功地选择了需要输入数据的窗口,但如果我切换窗口或更改聚焦字段,输入数据后会发生什么?文本突然消失这里是我处理的字段的UIspy日志 AutomationElement General Accessibility AccessKey: "" AcceleratorKey: "" IsKeyboardFocusable: "True" LabeledBy:
AutomationElement
General Accessibility
AccessKey: ""
AcceleratorKey: ""
IsKeyboardFocusable: "True"
LabeledBy: "(null)"
HelpText: ""
State
IsEnabled: "True"
HasKeyboardFocus: "False"
Identification
ClassName: "Edit"
ControlType: "ControlType.Edit"
Culture: "(null)"
AutomationId: "100"
LocalizedControlType: "edit"
Name: ""
ProcessId: "5172 (Winpoint)"
RuntimeId: "42 267278"
IsPassword: "False"
IsControlElement: "True"
IsContentElement: "True"
Visibility
BoundingRectangle: "(611, 286, 90, 20)"
ClickablePoint: "(null)"
IsOffscreen: "False"
ControlPatterns
Text
DocumentRange
Text: ""
Length: "0"
Bounding Rectangles: ""
AnimationStyleAttribute: "(not supported)"
BackgroundColorAttribute: "16777215"
BulletStyleAttribute: "(not supported)"
CapStyleAttribute: "None"
CultureAttribute: "(not supported)"
FontNameAttribute: "Microsoft Sans Serif"
FontSizeAttribute: "8"
FontWeightAttribute: "400"
ForegroundColorAttribute: "0"
HorizontalTextAlignmentAttribute: "Left"
IndentationFirstLineAttribute: "(not supported)"
IndentationLeadingAttribute: "(not supported)"
IndentationTrailingAttribute: "(not supported)"
IsHiddenAttribute: "(not supported)"
IsItalicAttribute: "False"
IsReadOnlyAttribute: "False"
IsSubscriptAttribute: "(not supported)"
IsSuperscriptAttribute: "(not supported)"
MarginBottomAttribute: "(not supported)"
MarginLeadingAttribute: "(not supported)"
MarginTopAttribute: "(not supported)"
MarginTrailingAttribute: "(not supported)"
OutlineStylesAttribute: "(not supported)"
OverlineColorAttribute: "(not supported)"
OverlineStyleAttribute: "(not supported)"
StrikethroughColorAttribute: "(not supported)"
StrikethroughStyleAttribute: "None"
TabsAttribute: "(not supported)"
TextFlowDirectionsAttribute: "(not supported)"
UnderlineColorAttribute: "(not supported)"
UnderlineStyleAttribute: "None"
Value
Value: ""
IsReadOnly: "False"
这是我正在使用的代码,当然我的目标是这个自动化id为100的文件
AutomationElement firstname = GetTextElement(appElement, "100");
if (firstname != null)
{
LogMessage("OK " + Environment.NewLine);
LogMessage("typing in the first name...");
{
ValuePattern firstnameval =
firstname.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
firstnameval.SetValue("basem22");
// firstnameval.Text("basem");
// var textbox = AutomationElement(scope, id);
ValuePattern p = firstname.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
p.SetValue("value");
因此,当我运行此代码时,该值会输入到文本框中,但如果我更改了foucs,它将消失我试图自动输入该表单并保存的任何想法。。谢谢如果有人遇到同样的情况,我会简单地使用这个答案。我发现,如果按下键盘键,文本会被保存,不会消失,看起来像是某种wpf延迟或其他什么,这里是修复代码
//add a letter and delete so text stay
System.Windows.Forms.SendKeys.SendWait("A");
System.Windows.Forms.SendKeys.SendWait("{HOME}{DELETE}");