Forum Discussion

lkonduru's avatar
lkonduru
Occasional Contributor
14 years ago

Page FindAll - could not return object array

Hi,



We have a page which dynamically gets rows at run-time, each row has button. I have written Jscript function which uses

Page.findAll(...) method to return array. But the property and prop value which i mention always return empty array with length 0.

Please find below the script and html elements from view source. I would really appreciate if you could help me.



Script:



function TestPage(url) {

  var process, page, buttons;

 

  process = Sys.Process("firefox")

  page = process.Page("*");

  page.ToUrl(url);

  buttons = page.FindAll("name", "popButton");    // below

  buttons = (new VBArray(buttons)).toArray();

 

  if (buttons.length > 0) {

    var i;

    for (i = 0; i < buttons .length; i++) {

      Log.Message("Detail: "+buttons );

    }

  }

  else {

    Log.Message("No Detail found.");

  }

 

}



Html View Source:  Can have following many submit buttons . In function, i am using "findAll("name", "popButton")



<input type="submit" class="popupScr" name="popButton" value='1001'

   onkeypress="verifyKey(this,event);" onClick="javascript&colon;NewWindow('/xxx/link.do?id=1001','popupwindow','600','500'); ">





<input type="submit" class="popupScr" name="popButton" value='1002'

   onkeypress="verifyKey(this,event);" onClick="javascript&colon;NewWindow('/xxx/link.do?id=1002','popupwindow','600','500'); ">





<input type="submit" class="popupScr" name="popButton" value='1003'

   onkeypress="verifyKey(this,event);" onClick="javascript&colon;NewWindow('/xxx/link.do?id=1003','popupwindow','600','500'); ">



Thanks


7 Replies


  • Hi,





    1. Set the search depth if your target objects are not direct children of the page.

    2. Since you're using a native name, the correct first parameter's value is "NativeWebObject.name".


  • lkonduru's avatar
    lkonduru
    Occasional Contributor
    Jared,



    Thanks. After adding depth parameter and changing params array  to "findAll" method it started working.



    I  have question on child/popup window control on TestComplete. I have following scenario



    I have a main web page, i am able to find specific buttons which i am interested. In a loop i am clicking the button through above

    script which in turn opens a popup. And on same popup i have couple of links to click and then close popup. Do the same in loop for other records on main page.



    1. Do i need to get new "Page" object for the popup window url (since the url is different from main window)?



    Thanks

  • Hi,





    If your pop-up is opened in a new tab or window, it is an individual page. So, to work with it, you need to obtain another Page object.


  • lkonduru's avatar
    lkonduru
    Occasional Contributor
    Jared,



    I tried creating a new "page" object for popup window, but while try to click on the link on the pop up page. I keep getting the object variable undefined. And also, the parent or main page window url is getting changed to popup url. Please find below the code snippet. I would appreciate your suggestion.





    function MainPageTest() {  

     ......

      for (var i = 0; i < xxx.length; i++) {

          xxx.click();  // from main page click, this opens up popup window

          page.Wait();

          

          var popUpUrl  = "http://popurl"; 

          var popUpPage = getPage(popUpUrl);   // getting "page" for popup url

          var tab = popUpPage.NativeWebObject.Find("href", "*" + "abc" + "*", "a");  // try to select a tab from pop up 

          // Note: tab value is coming as undefined

          tab.click();

      } 
    }



    Thanks



  • Hi,





    If you open your pop-up and look at the tree in the Object Browser, what do you see exactly? How many Page objects do you have, and what objects do you see under them?


  • lkonduru's avatar
    lkonduru
    Occasional Contributor
    Jared,



    In the object browser, there are 2 page objects. One for the main page and other for the pop up. I am attaching tree for the popup window below



    Sys.Process("firefox").Page("http://xxxxx:8080/app/x.do?x=123&tab=processing").Table(0).Cell(0, 0).Form("bnForm").Table(1).Cell(0, 0).Table(0).Cell(0, 7).Link(0)



    If i add the recorded mapped name in my script, test complete is recognizing the tab link in the pop up and is executing successfully.

    But it would be good to execute the same using Jscript and testcomplete property and methods.



    Thanks

  • Hi,





    The pop-up URL seems to be dynamic. Try using wildcards when you obtain the page (Sys.Process("firefox").Page("http://xxxxx:8080/app/x.*")).