googleid_118035
11 years agoContributor
How to find whether text fields is empty or not?
Hi,
I just need to check whether text fields of the web page is empty or not.
But is always return that text fields is not empty, even that text fields is empty.
Here is the sample code.
function test(){
if (My_Object != null){
Log.Message("Username field is not empty")
}
else {
Log.Message("Username field is empty")
}
}
..............
Thanks
Dev
I just need to check whether text fields of the web page is empty or not.
But is always return that text fields is not empty, even that text fields is empty.
Here is the sample code.
function test(){
if (My_Object != null){
Log.Message("Username field is not empty")
}
else {
Log.Message("Username field is empty")
}
}
..............
Thanks
Dev
- Just wrote this example real quick that hopefully helps you understand TC/JScript in conjunction with what you hope to accomplish:
//JScript example
function main(){
/*
open notepad and key in the word "hi"
*/
wshell = new ActiveXObject('WScript.Shell');
wshell.run("notepad");
var objToCheck = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1);
objToCheck.Keys("hi");
/*
call log.message and log the result of checkObjectText function
(with specified property value)
*/
Log.Message("The function returned the result of: " + checkObjectText(objToCheck,"wText","hi"));
/*
call log.message and log the result of checkObjectText function
(without specified property value and using a different property as an example)
*/
Log.Message("The function returned the result of: " + checkObjectText(objToCheck,"Enabled"));
}
function checkObjectText(myObj,propName,propValue){
/*
verify that the supplied object has the specified property
*/
if (aqObject.IsSupported(myObj,propName)){
/*
check to see if the objects property matches the specified propValue
if no propValue is specified then check to see if the property value has a specified length
*/
if (myObj[propName] == propValue || !propValue && myObj[propName].toString().length > 0){
return true;
}
}
/*
no previous criteria was met, return false
*/
return false;
}