Ask a Question

FindChild : Error: The object does not support this property or method

SOLVED
dicas
Occasional Contributor

FindChild : Error: The object does not support this property or method

Hello,

I tried to refactor my code with this below function, but i get the error in subject, when i try to access FindEx from Project.Variables.objstudioprocess

When I set a breakpoint at this line, and evaluate with debugtool:
Project.Variables.objstudioprocess   returns an 'Object'

That i can inspect and see the FindEx method available

When i try to evaluate with debugtool: 

Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000) 

It indeed find the tested object that i want.

When I continue the execution of the test it raises again the error.

See below the code : 

function addNewProjectVariable(parentName, variableName, type, arrayNames, arrayValues) {
if (!Project.Variables.VariableExists(variableName)) {
Project.Variables.AddVariable(variableName, type);
}
let propArray = arrayNames;
let propValues = arrayValues;


Project.Variables.variableName = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000) // Error: The object does not support this property or method.
Log.Message("systemView :"+Project.Variables.projectTreeView.Name)

}
5 REPLIES 5
tristaanogre
Esteemed Contributor

I think the problem is here.

 

Project.Variables.variableName = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000)

 

What is "variableName" in this context?  The code doesn't know.  You've created a variable with the NAME that is stored in variableName, but that variable isn't evaluated yet.

 

instead, replace with

 

Project.Variables.VariableByName(variableName) = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000)

 You need to use "VariableByName" because you need to evaluate what the variable is by the given name.  This is where your error is coming from, not the find.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
dicas
Occasional Contributor

Hello!

Actually,
to your question : What is "variableName" in this context?

 

function addNewProjectVariable(parentName, variableName, type, arrayNames, arrayValues) {
  if (!Project.Variables.VariableExists(variableName)) {
    Project.Variables.AddVariable(variableName, type);
  }  // Variable is created / evaluated here already 
  let propArray = arrayNames;
  let propValues = arrayValues;
  
 Project.Variables.VariableByName(variableName) = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000)
  Log.Message("systemView :"+Project.Variables.projectTreeView.Name)
  
}


See in my function i have a first part that deals with VariableName creation, isn't it already evaluated then ?

if (!Project.Variables.VariableExists(variableName)) {
    Project.Variables.AddVariable(variableName, type);
  }  // Variable is created / evaluated here already 



I tried your solution still : I got a new error 
ReferenceError: Invalid left-hand side in assignment 

tristaanogre
Esteemed Contributor

To answer your question:

 

Project.Variables.variableName is not defined because there isn't a variable named variableName.  There is a variable with the name that is the content of variableName.  

 

So, let's say variableName is "myVariable".  Then you would reference it as Project.Variables.myVariable or Project.Variables.VariableByName("myVariable").

 

Now, as to the other issue, this might be because you're using JavaScript and JavaScript can't assign values to indexed properties directly.  So, you'll need to re-do that line like so.

 

function addNewProjectVariable(parentName, variableName, type, arrayNames, arrayValues) {
  if (!Project.Variables.VariableExists(variableName)) {
    let localVariable = Project.Variables.AddVariable(variableName, type);
  }  // Variable is created / evaluated here already 
else {
    let localVariable = Project.Variables.VariableByName(variableName);
}
  let propArray = arrayNames;
  let propValues = arrayValues;
  
 localVariable = Project.Variables.objstudioprocess.FindEx(propArray,propValues,depth=5,true,delay = 5000)
  Log.Message("systemView :"+Project.Variables.projectTreeView.Name)
  
}

 

Alternatively, you may need to use the $set method to assign the variable value.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

@dicas 

And one more question:

 

Is it *really* needed to store a reference to the objstudioprocess process in the project variable?

Why not just use Aliases.objstudioprocess instead?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
sonya_m
SmartBear Alumni (Retired)

Thank you everyone!

 

@dicas was the advice helpful? Please let us know!


Sonya Mihaljova
Community and Education Specialist

cancel
Showing results for 
Search instead for 
Did you mean: