iam using UIAutomation in visual c # express 2010 i am trying to input so text boxes automatically in UI applicton i have succsuffully selected the window i need to input data in but what happens afer data is entered if i swiched windows or changed the focused filed the text suddenly disappears here is the UIspy log for the filed i work on
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"
and here is the code i am using of course iam targting this filed with the automation id of 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");
so when i run this code the "value" is entered on the textbox but if i changed foucs it disappears any ideas i am trying to input that form automatically and save it .. thanks
the answer i used simply in case any one had the same situation , i found if a keyboard key is pressed the text is saved and don't disappear seems like kind of wpf lag or something any ways here is the fixing code ,
//add a letter and delete so text stay
System.Windows.Forms.SendKeys.SendWait("A");
System.Windows.Forms.SendKeys.SendWait("{HOME}{DELETE}");