UIAutomation c#文本框随着鼠标点击或失去焦点而消失

时间:2014-10-28 11:24:11

标签: c# ui-automation microsoft-ui-automation

iam在visual c#express 2010中使用UIAutomation 我试图在UI应用程序中自动输入文本框我已经succsuffully选择了我需要输入数据的窗口,但是如果我改变了聚焦文件突然消失,那么在输入数据时会发生什么事情是UIspy日志我提交的文件

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");

因此,当我运行此代码时,"值"在文本框中输入,但如果我改变了它,它会消失任何想法,我试图自动输入该表格并保存它...谢谢

1 个答案:

答案 0 :(得分:0)

我使用的答案只是在任何一个人有相同情况的情况下,我发现如果按下键盘键,文本被保存并且不会消失,看起来像是某种wpf滞后或者其他任何方式在这里修复代码,

//add a letter and delete so text stay
                        System.Windows.Forms.SendKeys.SendWait("A");
                        System.Windows.Forms.SendKeys.SendWait("{HOME}{DELETE}");