在visual # express 2010中使用UIAutomation,我尝试输入文本框,所以在UI应用程序中,我已经成功地选择了我需要输入数据的窗口,但是如果输入了数据后,如果我使用了窗口或者更改了聚焦字段,文本就会突然消失,这里是我工作的字段的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"这是我正在使用的代码,当然,iam用自动化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,它就会消失,我试图自动输入该表单并保存它。谢谢
发布于 2014-10-30 07:38:46
我所用的答案仅仅是为了防止任何一个人遇到同样的情况,我发现如果按下键盘键,就会保存文本,并且不会消失,这看起来像是wpf滞后,或者其他什么方式都是修复代码,
//add a letter and delete so text stay
System.Windows.Forms.SendKeys.SendWait("A");
System.Windows.Forms.SendKeys.SendWait("{HOME}{DELETE}");https://stackoverflow.com/questions/26607104
复制相似问题