Forum Discussion
'Function received the text box object
Function ClearTextBox(outTxtObj)
If outTxtObj.text <> "" Then
ClearTextBox = False
'Locate mouse in the left corner of edit box
outTxtObj.Click 5,10
For i = 0 to Len(outTxtObj.text)
outTxtObj.keys("[Del]")
Next
End If
If outTxtObj.text = "" Then
ClearTextBox = True
Log.Message("Edit box was cleared")
End If
End Function
Nice one, Hagai.
I've got one in JScript I use before sending keys to a text object. Pass in whatever property you want to search for the text field with (I usually use Name, frequently with wildcards), the parameter, and the process. It also has to be a visible object.
function ClearTextObject(ByProperty, Parameter, ProcessName) { var PropArray, ValuesArray, Process, Target; var Depth = 5; PropArray = new Array(ByProperty, "Visible"); ValuesArray = new Array(Parameter, true); Process = Sys.Process(ProcessName); Target = Process.FindChild(PropArray, ValuesArray, Depth); try { if (Target.Exists) { var Text = Target.Text; var Length = Text.length; Target.Click(); Target.Keys("[End]"); Indicator.PushText("Backspacing the text away."); for (i = 0; i < Length; i++) { Target.Keys("[BS]"); } Indicator.PopText(); } else Log.Error("The object was not found."); } catch (err) { Log.Error(err.description) } }
- jsc10 years agoRegular Contributor
you can try
Obj.Keys("^aMyText")
so all text is selected (^a) and replaced withy "MyText"
Or Obj.SetText("MyText")
- Colin_McCrae10 years agoCommunity Hero
I would go with one of the methods that selects all and/or deletes/overwrites the text, and uses keys.
Personally, I think using methods such as "Clear" and "Value" and "SetText" are all bad. Reason being, your automated test is supposed to simulate a user. The user cannot invoke any of these methods. If you use them in your automated test, you are potentially going to miss defects as you are not using the application in the same way the user does.
Also, using these methods may not activate event triggers which should activate when "Keys" is used.
Thats my take on it anyway. Always emulate the user. Don't use methods the user can't get to just because it makes life easier. Thats not a proper test.
Related Content
- 11 years ago
Recent Discussions
- 3 days ago
- 3 days ago
- 6 days ago