Ask a Question

Searching for text

kinsleyd
Contributor

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
37 REPLIES 37
YMinaev
Staff

Hi Dave,



Do you have to search just for a single object? If you do, you can use the Find method in a loop until the object appears. Find returns a single object, not an array as FindAllChildren does. You just need to specify the property name, the text this property returns and a depth large enough (usually, 10 - 20 should do).

------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
tarleaa
Contributor

Hello, 


What if I want to find a text that is a date, which changes every day. Basically, I have a string that shows today's date + 1 day, and I have to check if this in fact today's date + 1 day. How can I do that? 



Thank you, 


Andrei


Hello Andrei,





Please post here the HTML text of the object containing this date. The HTML code is stored in the 'outerHTML' property of this object.
--
Dmitry Nikolaev

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
tarleaa
Contributor

Hello David, 


Here is the HTML text:


"<SPAN style="" id="ctl00_ContentPlaceHolder2_ucRegistrationStep2_lbBillingCondition">$5 1-day trial. <BR/><BR/>Your $5 1-day trial lasts until midnight on 4/23/2010. After your 1-day trial ends, your credit card on file will be charged the regular price of $25 per month for ............... </SPAN>"


The text I want found is "4/23/2010" which changes daily. 


Thank you, 


Andrei

Hello Andrei,




I recommend that you search for this object by its 'id' attribute. Here is a script demonstrating this:


...

  var page = ...;


  var obj = page.FindChild("NativeWebObject.id", "*_ucRegistrationStep2_lbBillingCondition", 100);


  if (false == obj.Exists) {


    Log.Error("The Billing Condition label is not found.");


  }

...
--
Dmitry Nikolaev

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
-Pv-
Occasional Contributor

I'm trying to get your example to work.  What is a valid entry for page = in your example?  Object Browser?  URL?

-Pv-



Hi Paul,





I meant the Page object (Sys.Process("iexplore").Page("*") or Aliases.iexplore.pageMyPage), but this can be any of the parent objects of the sought-for object.
--
Dmitry Nikolaev

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
-Pv-
Occasional Contributor

Andrei,

Thanks for your help.



I tried this...

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="Word.Document" name="ProgId" />
<meta content="Microsoft Word 12" name="Generator" />
<meta content="Microsoft Word 12" name="Originator" />





var MyItem =
Item_LocateInPage(Aliases.Sys.iexplore.pageStarlightLicenseServer20.document.all,

"sdfg");


  if(MyItem !=
null) {MyItem.Click()}



<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="Word.Document" name="ProgId" />
<meta content="Microsoft Word 12" name="Generator" />
<meta content="Microsoft Word 12" name="Originator" />





function Item_LocateInPage(TREE_MODEL_OBJECT, SearchText)

{


Log.Message("Item_LocateInPage")


if(TREE_MODEL_OBJECT.ChildCount < 1)


 
{Log.Message("No " + TREE_MODEL_OBJECT + " 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.


I also tried:


var MyItem =
Item_LocateInPage(Sys.Process("iexplore",
2).Page("http://127.0.0.1:3000/").document.all,

"sdfg");

-Pv-
Occasional Contributor

More...



You may not be able to tell from the image the item I'm trying to click is a direct child of the Object Tree .all, so should be able to find within 100 layers?

-Pv-
cancel
Showing results for 
Search instead for 
Did you mean: