Forum Discussion

NicolaFilosa_SE's avatar
NicolaFilosa_SE
Contributor
2 years ago

Array definition

Hi to everyone. I want to find and display 2 or more text elements in a web page. To do it I use the function FindAll, see below:

Targets=Aliases.browser.pageEquipment.FindElement("//se-app/div/div/div/div/div[contains(@class, 'flex-1')]").FindAll(PropArray, ValuesArray, 15, 1000).toArray();
for (var i=0; i<Targets.length;i++)
{Log.Message(Targets[i].contentText)}

 

I define the property using the variable PropArray:

var PropArray = "contentText";

 

For the values I tried to use an array but nothing works. If my elements are for example a and b how can I define the variable ValuesArray?

Thanks in advance

  • I tried using Find instead of FindAll but it does not find the string and so does not higlight the object.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You should breakdown your lines of code,

     

    var target1 = Aliases.browser.pageEquipment.FindElement("//se-app/div/div/div/div/div[contains(@class, 'flex-1')]");
    
    var PropArray = ["contentText", "link"];
    var ValuesArray = ["a", "b"];
    var target2 = target1.FindAll(PropArray, ValuesArray, 15);
    
    for (var i = 0;  i < target2.length; i++) {
        Log.Message(target2[i].contentText)
    }

     

    So it's easier to debug, and check the values.

     

    Check target1 is returning data that you expect, followed by target2.

     

    Also, I'm not sure what 1000 is used for in FindAll? The fourth parameter should take a Boolean value.

    • NicolaFilosa_SE's avatar
      NicolaFilosa_SE
      Contributor

      I tried this solution but it nly displays the first string, "a". It seems that he does not recognizes ValuesArray as an array

    • NicolaFilosa_SE's avatar
      NicolaFilosa_SE
      Contributor

      I tried to log the length of the array that comes from the FindAll function and it is 1. It seems it does not search the elements containing the second string

      var findTargets = Aliases.browser.pageEquipment.FindElement("//se-app/div/div/div/div/div[contains(@class, 'flex-1')]");
      var PropArray = ["contentText", "contentText"];
      var ValuesArray = ["INP99999", "TelevisGo"];
      var Targets = findTargets.FindAll(PropArray, ValuesArray, 20, true);
      Log.Message(Targets.length);
      for (var i=0; i<Targets.length;i++)
      {Log.Message(Targets[i].contentText)}

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Or try,

     

     

    var PropArray = new Array ("contentText", "link");
    var ValuesArray = new Array ("a", "b");
    var target2 = target1.FindAll(PropArray, ValuesArray, 15);

     

     

    Is it actually printing "a" to the log? Is it many a's or just the one?

     

    Also, the b's might have a control character next to it, so it might not match. It's difficult to say, without seeing what you are trying to search for. Screenshots help.

     

    In this example,

    the menu items are displayed

     

    • NicolaFilosa_SE's avatar
      NicolaFilosa_SE
      Contributor

      I don't know why but now it prints 0. I attach here the screenshot so you can understand it better.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Beneath var findTargers, insert the following code, to see if it highlights the correct object that you are expecting?

    Sys.HighlightObject(findTargets);

    And does the following code, also highlights the correct object that you are expecting?

    var Targets = findTargets.FindAll("contentText", "DR 4010PT100");
    Sys.HighlightObject(Targets);

    and

    var Targets = findTargets.FindAll("contentText", "TelevisGo");
    Sys.HighlightObject(Targets);

    This is to check that the objects belong to the correct xpath that you have specified.

    • NicolaFilosa_SE's avatar
      NicolaFilosa_SE
      Contributor

      If I use the first code TC higlights the object of the variable findTargets:

      var findTargets = Aliases.browser.pageEquipment.FindElement("//se-app/div/div/div/div/div[contains(@class, 'flex-1')]"); (first image, 26kb)

      In the log it continues to display only the value 0.

      If I try the second code the following message appears (second image, 9 kb).

      I tried also to simplify the code but the same message appears:

      var findTargets = Aliases.browser.pageEquipment.FindElement("//se-app/div/div/div/div/div[contains(@class, 'flex-1')]");
      var Targets = findTargets.FindAll("contentText", "DR 4010PT100");
      Sys.HighlightObject(Targets);

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I made a slight mistake, FindAll() should have been Find(), as Sys.HighlightObject can only highlight an object and not a list of objects!

     

    For the time being, ignore the value. The idea here, is to test that your code is finding the correct object.

     

    If Find("contentText", "DR 4010PT100") is found, but not Find("contentText", "TelevisGo"). Then it implies that Find("contentText", "TelevisGo") is not a child element of FindElement("//se-app/div/div/div/div/div[contains(@class, 'flex-1')]");

     

    What does the Object Browser tree view look like for these items?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Then it implies that those child elements do not belong to FindElement("//se-app/div/div/div/div/div[contains(@class, 'flex-1')]");

     

    What does the Object Browser tree view look like for these items?

     

    • NicolaFilosa_SE's avatar
      NicolaFilosa_SE
      Contributor

      They belong both, because if I do a generic FindAll, like this:

      Targets=Aliases.browser.pageEquipment.FindElement("//se-app/div/div/div/div/div[contains(@class, 'flex-1')]").FindAll("contentText", "*", 15, 1000).toArray();
      Log.Message(Targets.length);
      for (var i=0; i<Targets.length;i++)
      {Log.Message(Targets[i].contentText)}

      the log is the one in the images attacched

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I'm still not sure what 1000 is in FindAll("contentText", "*", 15, 1000)!?

     

    Looking at your screenshot, it looks like the value should be "DR 4010 PT100" (note the spacing) and not "DR 4010PT100"

    Also, you can't do the following, as PropArray property values have to be unique.

    var PropArray = ["contentText", "contentText"];
    var ValuesArray = ["INP99999", "TelevisGo"];
    var Targets = findTargets.FindAll(PropArray, ValuesArray, 20, true);

    e.g.

    var PropArray = ["contentText", "ObjectType"];
    var ValuesArray = ["*", "Link"];

     

    Does this work?

     

    function test()
    {
        var Targets = Aliases.browser.pageEquipment.FindElement("//se-app/div/div/div/div/div[contains(@class, 'flex-1')]");
        var Items = Targets.FindAll("contentText", "*", 1000, true); // or try with Targets.FindAll("contentText", "*", 1000, true).toArray();
        Log.Message(Items.length);
        for (var i = 0; i < Items.length; i++) {
            Log.Message(Items[i].contentText)
        }
    }

     

     

     

  • If I substitute 1000 with true nothing changes. Yes, the correct string is "DR 4010 PT100" but I tried your codes with the correct string. The code that you sent me works as the one that I sent to you, so it logs all the strings contained in the page

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Note - the declaration is TestObj.FindAll(PropNames, PropValues, Depth, RefreshTree). Fourth parameter accepts a Boolean value.

     

    If you want to find different contentText values, create a function and pass a parameter value to be used for PropValues. If your finding more items then expected, you can narrow you search by adding additional properties.