Searching for text
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2010
06:25 AM
02-02-2010
06:25 AM
Searching for text
I'm searching for an effecient way to look at the loaded page and search for some text, specifically the text one can expect if the page returns a javascript error or finds no matching documents, which the developers have made global. The trouble is I can not predict exactly where it'll be on the page. I've tried using an if .... exists statement, but then I get a bunch of errors as its trying to find the frame I typically see the text appearing in which isn't there if the page does load/present documents properly, if that makes sense. My next thought was FindAllChildren, but then I'd find myself looking at an array, which I guess is possible, but seems cludgey somehow. Any thoughts?
TIA - Dave
Got the findallchildren logic working, but still seems cludgey
TIA - Dave
Got the findallchildren logic working, but still seems cludgey
37 REPLIES 37
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2010
05:57 AM
04-23-2010
05:57 AM
Sorry David I should have addressed the last two posts to you. More tired than I thought. Hope this helps Andrei also 😉
-Pv-
-Pv-
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010
02:12 AM
04-26-2010
02:12 AM
Hi Paul,
Your code is invalid. The following line:
if(TREE_MODEL_OBJECT.ChildCount < 1)
will not allow your code to find anything. I am guessing that you wanted to use the '>' (greater then) operator instead of '<' (less than).
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010
02:51 AM
04-26-2010
02:51 AM
Thank you for responding.
From my understanding, the IF statement in question should not be affecting the portion of the script containing the FindChild:
if(TREE_MODEL_OBJECT.ChildCount < 1)
{Log.Message("No Children Detected in search"); return null}
Log.Message("Searching " + TREE_MODEL_OBJECT.ChildCount + " children...");
var obj = TREE_MODEL_OBJECT.FindChild("NativeWebObject.outerText", SearchText, 100);
if (false == obj.Exists)
{
Log.Error(SearchText + " not found.");
return null;
}
else
return obj;
=============================
Since my script is returning the number of children found and not "No Children..." I think the FindChild is executing but returning nothing unaffected by the <1.
Appreciate your help.
-Pv-
From my understanding, the IF statement in question should not be affecting the portion of the script containing the FindChild:
if(TREE_MODEL_OBJECT.ChildCount < 1)
{Log.Message("No Children Detected in search"); return null}
Log.Message("Searching " + TREE_MODEL_OBJECT.ChildCount + " children...");
var obj = TREE_MODEL_OBJECT.FindChild("NativeWebObject.outerText", SearchText, 100);
if (false == obj.Exists)
{
Log.Error(SearchText + " not found.");
return null;
}
else
return obj;
=============================
Results:
Item_LocateInPage
Searching 764 children...
sdfg not found.
Since my script is returning the number of children found and not "No Children..." I think the FindChild is executing but returning nothing unaffected by the <1.
Appreciate your help.
-Pv-
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010
03:11 AM
04-26-2010
03:11 AM
Hi Paul,
From my understanding, the IF statement in question should not be affecting the portion of the script containing the FindChild:
if(TREE_MODEL_OBJECT.ChildCount < 1)
{Log.Message("No Children Detected in search"); return null}
Sorry, I missed the '}' character at the end of this line. That is why I always put it to a new line. 🙂
I looked at your script again and think that the problem is caused by the fact that the 'NativeWebObject' namespace does not have the 'outerText' property. Try using this property directly:
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010
03:51 AM
04-26-2010
03:51 AM
Thanks again for your help.
I could not use "id" because in ExtJS generated ID properties are dynamic and more often than not, non-repeatable. In our current app, many of the page items I need to locate have varying properties which have some kind of uniqueness, so I need to be flexible about which property I use to find something, but I can almost never rely on IDs.
When I need to generate, then click on list items generated in real time, the IDs ALWAYS change so cannot map them.
I hope to let you know soon if this worked.
-Pv-
I could not use "id" because in ExtJS generated ID properties are dynamic and more often than not, non-repeatable. In our current app, many of the page items I need to locate have varying properties which have some kind of uniqueness, so I need to be flexible about which property I use to find something, but I can almost never rely on IDs.
When I need to generate, then click on list items generated in real time, the IDs ALWAYS change so cannot map them.
I hope to let you know soon if this worked.
-Pv-
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2010
06:32 AM
04-26-2010
06:32 AM
Works Great!
-Pv-
-Pv-
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2010
12:34 AM
04-27-2010
12:34 AM
Hi Paul,
I am glad to hear that this works for you.
Please note that you must not use the native 'id' attribute to map objects in your application. You can use other properties to do this. If there are any ambiguity on any of the hierarchy levels, I recommend that you consider using the required children feature as it can be a good solution in this case. You can find more information on this feature in the Specifying Child Objects Required for Mapped Object Identification help topic.
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2010
02:41 AM
05-06-2010
02:41 AM
I cannot use mapping because I need cross-browser code and the pages are too dynamic to map reliably.
I've also learned timing is a critical issue in the search for ExtJS items in the object tree. There appears to be two problems:
1) The page has to completely redrawn after a page request caused by a screen button click.
2) After the page is drawn, I cannot serach the object tree successfully until the object tree has been refreshed manually. The "simple" pages I'm testing right now have between 400 and 800 items per page while there are only 5 to 10 controls on the page.
Although this isn't the best place to put the delays and refresh, this way I don't have to think about whether I need to do it or not and just accept the 2 seconds overhead per search.
Example:
MyItem = Item_LocateInPage(BrowserProcess, "innerHTML", "Cancel");
if(MyItem != null) {MyItem.Click();}
function Item_LocateInPage(TREE_MODEL_OBJECT, PropertyType ,SearchText)
{
Log.Message("Item_LocateInPage: " + PropertyType + " " + "\'" + SearchText + "\'")
var obj = null;
Delay(1500); // Wait for page to draw
TREE_MODEL_OBJECT.Refresh();
Delay(500); // Wait for object model to refresh
if(!TREE_MODEL_OBJECT.ChildCount || TREE_MODEL_OBJECT.ChildCount == undefined)
{Log.Warning("No " + TREE_MODEL_OBJECT + " Children Detected in search"); return null}
Log.Message("Searching " + TREE_MODEL_OBJECT.ChildCount + " children...");
if(PropertyType == "idStr")
var obj = TREE_MODEL_OBJECT.FindChild("idStr", SearchText, 100);
if(PropertyType == "outerText")
var obj = TREE_MODEL_OBJECT.FindChild("outerText", SearchText, 100);
if(PropertyType == "Name")
var obj = TREE_MODEL_OBJECT.FindChild("Name", SearchText, 100);
if(PropertyType == "NodeName")
var obj = TREE_MODEL_OBJECT.FindChild("NodeName", SearchText, 100);
if(PropertyType == "value")
var obj = TREE_MODEL_OBJECT.FindChild("value", SearchText, 100);
if(PropertyType == "textContent")
var obj = TREE_MODEL_OBJECT.FindChild("textContent", SearchText, 100);
if(PropertyType == "innerHTML")
var obj = TREE_MODEL_OBJECT.FindChild("innerHTML", SearchText, 100);
if ((obj == null) || (false == obj.Exists))
{
Log.Warning("Not Found.");
return null;
}
else
return obj;
}
-Pv-
I've also learned timing is a critical issue in the search for ExtJS items in the object tree. There appears to be two problems:
1) The page has to completely redrawn after a page request caused by a screen button click.
2) After the page is drawn, I cannot serach the object tree successfully until the object tree has been refreshed manually. The "simple" pages I'm testing right now have between 400 and 800 items per page while there are only 5 to 10 controls on the page.
Although this isn't the best place to put the delays and refresh, this way I don't have to think about whether I need to do it or not and just accept the 2 seconds overhead per search.
Example:
MyItem = Item_LocateInPage(BrowserProcess, "innerHTML", "Cancel");
if(MyItem != null) {MyItem.Click();}
function Item_LocateInPage(TREE_MODEL_OBJECT, PropertyType ,SearchText)
{
Log.Message("Item_LocateInPage: " + PropertyType + " " + "\'" + SearchText + "\'")
var obj = null;
Delay(1500); // Wait for page to draw
TREE_MODEL_OBJECT.Refresh();
Delay(500); // Wait for object model to refresh
if(!TREE_MODEL_OBJECT.ChildCount || TREE_MODEL_OBJECT.ChildCount == undefined)
{Log.Warning("No " + TREE_MODEL_OBJECT + " Children Detected in search"); return null}
Log.Message("Searching " + TREE_MODEL_OBJECT.ChildCount + " children...");
if(PropertyType == "idStr")
var obj = TREE_MODEL_OBJECT.FindChild("idStr", SearchText, 100);
if(PropertyType == "outerText")
var obj = TREE_MODEL_OBJECT.FindChild("outerText", SearchText, 100);
if(PropertyType == "Name")
var obj = TREE_MODEL_OBJECT.FindChild("Name", SearchText, 100);
if(PropertyType == "NodeName")
var obj = TREE_MODEL_OBJECT.FindChild("NodeName", SearchText, 100);
if(PropertyType == "value")
var obj = TREE_MODEL_OBJECT.FindChild("value", SearchText, 100);
if(PropertyType == "textContent")
var obj = TREE_MODEL_OBJECT.FindChild("textContent", SearchText, 100);
if(PropertyType == "innerHTML")
var obj = TREE_MODEL_OBJECT.FindChild("innerHTML", SearchText, 100);
if ((obj == null) || (false == obj.Exists))
{
Log.Warning("Not Found.");
return null;
}
else
return obj;
}
-Pv-
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2010
04:08 AM
05-06-2010
04:08 AM
Hi Paul,
I suggest that you use the RefreshMappingInfo method in order to refresh the Name Mapping tree since the Refresh method does not refresh it. Information on this method can be found in the RefreshMappingInfo Method help topic.
Also, since you are searching for objects using the FindChild method which requires writing tests manually, I recommend you looking at the Extended Find feature of Name Mapping. You can find information on this feature in the Using Extended Search Criteria for Mapped Object Identification help topic. Please note that TestComplete cannot automatically record actions over objects mapped with this feature.
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2010
06:05 AM
05-06-2010
06:05 AM
I've looked at those things repeatedly and they don't seem to apply because I'm not using name mapping.
-Pv-
-Pv-
