Forum Discussion

romanmfs's avatar
Frequent Contributor
7 years ago

Searching for an element containing desired text

Hi All!

I am trying to create a test case where I would search for specific word on the site and as a reuslt give me an alert/ warning of either the searched word exists or not.


Can anybody advise what I am doing wrong?

the code I have brakes right away with an error message cannot navigate to specific url and does not even open the browser. 


I am using smartbear website as an example, and we are searching for the work "cake".



function Test()

  var url = "";
  var browser = Sys.Browser("*");
  var page = browser.Page("*");

  var str = "*Cake*"; // Note that we used the * wildcards to specify the search pattern

  // Searches for the text in the page
  obj = page.NativeWebObject.Find("contentText", str, "A");

  // Checks the result
  if (obj.Exists)
    Log.Message("Object containing text '" + str + "' is found", obj.FullName);
    Log.Warning("Object containing text '" + str + "' was not found.");