Forum Discussion

sarya's avatar
sarya
Frequent Contributor
15 years ago

Clicking on folder expand icon on web page to show sub-folders

Hi,



I am trying to click on the '+' icon adjacent to 'Demo' folder and expand the sub-folders underneath it.

I used the code like this but it expands some other folder everytime I run this code. The problem is that all the '+' icons on the webpage have same object properties and only the ID differs and if I use the ID to click that icon,the next time when I delete and recreate the folder,it changes and code fails. Can someone please tell me how to go about this?



all = page.document.frames.ifmfolder.document.all;


a = page.NAtiveWebObject.Find("outerText","demo");


icon = a.parent.FindChild("namePropStr","plus.gif");


icon.onclick();



Thanks,

Sumedha

  • Hi,



    As I understand all these '+' icons have no unique property (except for ID which is changed dynamically), and they have the same parent object (I mean all these icons are under a.parent and that's why you can click wrong icon each time).



    You can try to search needed icon by its Y coordinate (it may be "Top", "ScreenTop" or some another property defining vertical coordinate), taking into account that it should be on the same level as "demo" folder.

    So you should find all objects with "namePropStr" property equal to "plus.gif" and take the one which has "Top" property approximately equal "demo" item's Top property (taking into account that "+" icon may be shifted by several pixels in comparison to "demo)



    Let's take that your icon is on the same level as "demo" +- 5 pixels, then the code will be like this:



    all = page.document.frames.ifmfolder.document.all;

    a = page.NAtiveWebObject.Find("outerText","demo");



    icons = a.parent.FindAll("namePropStr","plus.gif", 1);

    icons = VBArray(icons).toArray();



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

    {

     
    if ((icons.Top>a.Top-5)&&(icons.Top<a.Top+5))

    {icon = icons; break}

    }



    icon.Click();
  • sarya's avatar
    sarya
    Frequent Contributor
    Hey Pavel,



    Thanks for the reply.I searched for the "Top" and "ScreenTop" property for the "+" icons on the same level as demo but each one of them is having a different value. None of them has a matching value .Then how to figure out only that particulr icon.



    Thanks,

    Sumedha
  • sarya's avatar
    sarya
    Frequent Contributor
    Hey Pavel,



    Thanks so much for your help .It solved my problem.The code that you give ran perfectly fine.Just I was not able to get some piece of the code where you mentioned the 'For' loop.So if you can explain me that.



    Let's take that your icon is on the same level as "demo" +- 5 pixels, then the code will be like this:



    all = page.document.frames.ifmfolder.document.all;

    a = page.NAtiveWebObject.Find("outerText","demo");



    icons = a.parent.FindAll("namePropStr","plus.gif", 1);

    icons = VBArray(icons).toArray();



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

    {

      if ((icons.Top>a.Top-5)&&(icons.Top<a.Top+5))

    {icon = icons; break}

    }



    icon.Click();



    Thanks,

    Sumedha




  • Hi,



     
     As I said they may differ by several pixels, and can be not exactly on the same level. That's why I supposed that your icon's "Top" property differs from the necessary folder's "Top" property not more than by 5 pixels. Check this in your object browser, it may appear to be that its just one pixel. 
        


       
     What exactly you did not understand in the code? I added some comments below



    //obtaining your "demo" folder

    a = page.NAtiveWebObject.Find("outerText","demo");



    //getting all plus.gif icons under "demo" folder's parent object, the result will be array of objects

    icons = a.parent.FindAll("namePropStr","plus.gif", 1);

    //converting this array to JScript array

    icons = VBArray(icons).toArray();



    //iterating through all array elements

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

    {

    // checking each element, if its Top value equal to "demo" folder's Top value +-5 pixels then its the icon you need

    if ((icons.Top>a.Top-5)&&(icons.Top<a.Top+5))

    {icon = icons; break}

    }



    icon.Click();
  • sarya's avatar
    sarya
    Frequent Contributor
    Hi Pavel,



    Actually I was not able to fully understand the below code where we need to look +- 5 pixels..I looked at the object properties and saw that for one folder,the value for the 'Top' property for the icon  is 162 and for the very next icon is 178 which is more tan 5 pixels.



    // checking each element, if its Top value equal to "demo" folder's Top value +-5 pixels then its the icon you need

    if ((icons.Top>a.Top-5)&&(icons.Top<a.Top+5))

    {icon = icons; break}



    I now understood how to find the particular icon by looping through Top's value +-5 pixels .



    thanks,

    Sumedha