首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIAutomation c#文本框因鼠标单击或失去焦点而消失。

UIAutomation c#文本框因鼠标单击或失去焦点而消失。
EN

Stack Overflow用户
提问于 2014-10-28 11:24:11
回答 1查看 901关注 0票数 0

在visual # express 2010中使用UIAutomation,我尝试输入文本框,所以在UI应用程序中,我已经成功地选择了我需要输入数据的窗口,但是如果输入了数据后,如果我使用了窗口或者更改了聚焦字段,文本就会突然消失,这里是我工作的字段的UIspy日志。

代码语言:javascript
运行
复制
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"

这是我正在使用的代码,当然,iam用自动化id 100来处理这个字段

代码语言:javascript
运行
复制
                    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,它就会消失,我试图自动输入该表单并保存它。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-30 07:38:46

我所用的答案仅仅是为了防止任何一个人遇到同样的情况,我发现如果按下键盘键,就会保存文本,并且不会消失,这看起来像是wpf滞后,或者其他什么方式都是修复代码,

代码语言:javascript
运行
复制
//add a letter and delete so text stay
                        System.Windows.Forms.SendKeys.SendWait("A");
                        System.Windows.Forms.SendKeys.SendWait("{HOME}{DELETE}");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26607104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档