Forum Discussion

Mpeterson's avatar
Mpeterson
Occasional Contributor
14 years ago

Convert String output from array to Object

I have created an array and populated it. Then i pull out an item and assign it to a variable it is a string. I want to use that variable in a line of code that is pointing to a location ( a checkbox) and that needs to be an object (apparently). I have tried creating variables as objects but to no avail...perhaps i am going about this all wrong i don't know.

What I am doing is using DDT w/ an excel driver.

The page I am addressing has a lot of checkboxes on it that i need to clear or check dependant on the T/F value on the spreadsheet.



I have already used the driver to address other dropdowns on the page at this point. Then here I launch in to this 'for' statment to walk though the array to locate and select the checkboxes:

for (i = 0; i < checkBoxes.length; i++) //checkboxes array is stepping though the names


{


CB = (checkBoxes.innerText) //Assign values to variables to populate the querry string to see if the checkbox is selected (T/F)


CB1 = (checkBoxes.RowIndex)


CB2 = (checkBoxes.ColumnIndex)


CB5 = (checkBoxes.Name)   //gives me the string "Cell 162,4"


Log.Message(DDT.CurrentDriver.Value(CB));    //the variable from the array works for this part.....


table.Cell(162,4).Checkbox("ctl00_PageCenterContentPlaceHolder_DomainDropCheckBoxList_*").ClickChecked(false);

  //I uncheck the box using the correct value for the cell to make sure everything else works


table.CB5.Checkbox("ctl00_PageCenterContentPlaceHolder_DomainDropCheckBoxList_*").ClickChecked(DDT.CurrentDriver.Value(CB));


//when i run this line it cannot find the object "Cell"



So that is the problem i think. I am not presenting the value in a correct way for the system to find my checkbox.



Any suggesting would be great this ones got me stumped.



Mark

6 Replies

  • Hi,



    You need to use eval. For example:

    ...

    CB = eval(checkBoxes).innerText;

    ...

  • Mpeterson's avatar
    Mpeterson
    Occasional Contributor
    Thanks for the advise but I am not getting the expected result

    function ConvertArray(AArray)


    {


    // Uses the Dictionary object to convert a JScript array


    var objDict = new ActiveXObject("Scripting.Dictionary");


    objDict.RemoveAll();


    for (var j in AArray)


    objDict.Add(j, AArray);


    return objDict.Items();


    }


     


    怀


     


     


    Log.Message ("Total number of found checkboxes:" + checkBoxes.length); //log how many items are in the array


     


    for (i = 0; i < checkBoxes.length; i++) //checkboxes array is stepping though the names


    {


    CB = (checkBoxes.innerText);


    CB = (checkBoxes.innerText); //Assign values to variables to populate the querry string to see if the checkbox is selected (T/F)


    CB1 = (checkBoxes.RowIndex);


    CB2 = (checkBoxes.ColumnIndex);


    CB5 = eval(checkBoxes).Name;


     


    Log.Message(DDT.CurrentDriver.Value(CB));


     (line 1) table.Cell(162,4).Checkbox("ctl00_PageCenterContentPlaceHolder_DomainDropCheckBoxList_814").ClickChecked(false);


    (line2) table.CB5.Checkbox("ctl00_PageCenterContentPlaceHolder_DomainDropCheckBoxList_814").ClickChecked(DDT.CurrentDriver.Value(CB));




    Line 1 is the same is the same as line two ( pointing at the same checkbox) the line using 'cell(162,4)' works fine. line 2 'cannot find Cell' i noticed that when I evaluate table.'Cell(162,4).'I get values, when I evaluate 'table.CB5' i get (Null Non-Automation Object)



    So am i not using the eval properly or do i have another issue?

    Thanks,

    Mark
  • Hi,



    You cannot use strings like this. CB5 = eval(checkBoxes).Name gives you a string in CB5, it is not a property, not an object, it is just a variable which contains a string value.



    table.CB5.Checkbox - table doesn't have a property named 'CB5', so this code fails. You can do something like this:

    ...

    CB5 = eval(checkBoxes).Name;

    //...

    eval(table.Name + "." + CB5).Checkbox("ctl00_PageCenterContentPlaceHolder_DomainDropCheckBoxList_814").ClickChecked(DDT.CurrentDriver.Value(CB));

    ...

  • Mpeterson's avatar
    Mpeterson
    Occasional Contributor
    I am still getting errors, " Sysnode is undefined " is the new one I get at the last line is this chunk of code. Could the issue be the way I am creating the array ? Sorry to be a total noob at this but i cannot seem to get this going......



     


    var p, w, CheckBoxes, i, panel, Name1;


     


    Log.Message(DDT.CurrentDriver.Value("Filter type"))


     


    //define variables for Filter type and Condition dropdown boxes


    iexplore = Sys.Process("iexplore", 2);


    page = iexplore.Page("https://daffy-v5.phxpd.local/ReportingSystem/Object/ObjectQuery.aspx*");


    panel = page.Form("aspnetForm").Panel("ctl00_PageContentPanel").Panel(0).Panel(1);


    table = (panel.table("ctl00_PageCenterContentPlaceHolder_DomainDropCheckBoxList"));


     


    // Select the filter drop downs and insert values from spreadsheet


    if(panel.WaitSelect("ctl00_PageCenterContentPlaceHolder_filterFieldList", 0).Exists)


    panel.Select("ctl00_PageCenterContentPlaceHolder_filterFieldList").ClickItem(DDT.CurrentDriver.Value("Filter type"));


     


    if(panel.WaitSelect("ctl00_PageCenterContentPlaceHolder_DomainFilterDropDownList", 0).Exists)


    Delay(500)


    panel.Select("ctl00_PageCenterContentPlaceHolder_DomainFilterDropDownList").ClickItem(DDT.CurrentDriver.Value("Condition"));//Is Null;Is Not Null;Is one of;Is not any of


     


    {


    var w, PropArray, ValuesArray, ConvertedPropArray, ConvertedValuesArray, i;


    // Obtain the panel


    w = Sys.Process("iexplore", 2).Page("https://daffy-v5.phxpd.local/ReportingSystem/Object/ObjectQuery.aspx?template=A1a255fbd-49c9-42a1-9de5-e4eff884520b").Form("aspnetForm").Panel("ctl00_PageContentPanel").Panel(0).Panel(1).Table("ctl00_PageCenterContentPlaceHolder_DomainDropCheckBoxList");


     


    // Specify the sought-for property names ..... I do not totally understand this selection


    PropArray = new Array ("all");


    // Specify the sought-for property values


    ValuesArray = new Array ("*");



    // Converts arrays


    ConvertedPropArray = ConvertArray(PropArray);


    ConvertedValuesArray = ConvertArray(ValuesArray);


    // Find all checkboxes in the window (defined as the variable w)


    checkBoxes = w.FindAllChildren(ConvertedPropArray, ConvertedValuesArray, 1);


    checkBoxes = VBArray(checkBoxes).toArray();


     


    }


    function ConvertArray(AArray)


    {


    // Uses the Dictionary object to convert a JScript array


    var objDict = new ActiveXObject("Scripting.Dictionary");


    objDict.RemoveAll();


    for (var j in AArray)


    objDict.Add(j, AArray);


    return objDict.Items();


    }


     


    怀


     


     


    Log.Message ("Total number of found checkboxes:" + checkBoxes.Length); //log how many items are in the array


     


    for (i = 0; i < checkBoxes.length; i++) //checkboxes array is stepping though the names


    {


    CB = (checkBoxes.innerText); //Assign values to variables to populate the querry string to see if the checkbox is selected (T/F)


     


    CB5 = eval(checkBoxes).Name;


     


    Log.Message(DDT.CurrentDriver.Value(CB));


     


    table.Cell(162,4).Checkbox("ctl00_PageCenterContentPlaceHolder_DomainDropCheckBoxList_814").ClickChecked(false);


    eval(table.Name + "." + CB5).Checkbox("ctl00_PageCenterContentPlaceHolder_DomainDropCheckBoxList_814").ClickChecked(DDT.CurrentDriver.Value(CB));


     


     


    }

  • Hi,



    // Specify the sought-for property names ..... I do not totally understand this selection



    PropArray = new Array ("all");



    // Specify the sought-for property values



    ValuesArray = new Array ("*");




    I'm not quite sure what you're trying to do in these lines, but if you want to find all check boxes, you need to use the ObjectType property with the appropriate value ("checkbox"). Also, obtaining the name of each object as a string and evaluating it here are not needed at all. FindAllChildren returns an array of objects, you already have object references in 'checkBoxes', there's no need to reobtain them by name.
  • Mpeterson's avatar
    Mpeterson
    Occasional Contributor
    Ok I have it working, the eval was the ticket to turn my string into an object so i could address it with the ClickedChecked Command.



    CB = (checkBoxes.innertext); //looks at the indexed object at this point and passes the value of innertext to the variable 'CB'


    CB1 = (checkBoxes1.Name); //looks at the indexed object at this point and passes the value of Name to the variable 'CB1'


    CB2 = (checkBoxes2.Name);


    CB6 = (w.FullName);


    Log.Message(CB);


    CB7 = eval(CB6+"."+CB2+"."+CB1);  //combine my string variables use eval to turn it into an object


    CB7.ClickChecked(DDT.CurrentDriver.Value(CB));



    Thanks ,

    Mark