Circular reference

'return go.Diagram.fromDiv("id")'

I am executing this script to get the values from browser using selenium …
Essentially translating to Selenium as below

 await browser.executeScriptWithDescription('return go.Diagram.fromDiv("id")', "");

This gives

javascript error: circular reference
  (Session info: chrome=85.0.4183.83)
  (Driver info: chromedriver=85.0.4183.87 (..-refs/branch-heads/4183@{#1689}),platform=)

while other scripts does not give any circular reference error …

await browser.executeScriptWithDescription('return go.Diagram.fromDiv("id").findNodeForKey(1).location', ""); 

etc … they don’t give this error.

@walter can you kindly help

Within nodes there are buttons etc … They are not showing in the model … i am trying to get their location to get the robotjs to move to their location , i need help, thanks

I don’t know, but I am guessing that returning a JavaScript value to Selenium requires serialization to/from JSON-formatted text.

Any instance of Diagram or Tool or Node or Link or TextBlock or Picture cannot be serialized because they contain references to other objects that have back-references (either directly or indirectly).

Walter I am trying to get the objects within objects. Let me explain. Now there are 4 nodes initially. When we drag and drop a fifth node comes up, I am able to get the model data using node counts and knowing which node came newly.

Case 1: Now what i am trying to find is - a object within first node is there. I don’t know what kind of object that is or how to get it and get the co ordinates. This is small object which when clicked gives context menu to clear or add other objects.

Similarly case 2,. when newly added object is dragged into node 1, it creates node 2. Similarly though i can get the new node , how to get the smaller objects within the node ?

Like what could they be called ? inports and out ports ? But the inports and outports dont have the location x and y details. So using the model.nodedataarray and object value that it provides is useless.

how to get every single object/diagram within a dragged diagram inside canvas pls?

You can iterate over all of the Nodes in a Diagram via Diagram.nodes. Similarly for Links, use Diagram.links.

Once you have a Node or a Link, you can traverse its visual tree. If the object is a Panel, you can iterate over its Panel.elements.

If you care about specific ports on a Node, you can iterate over the node’s Node.ports. But if there is only one logical port per node, use the methods on the Node class to navigate through the diagram’s graph.

Ok, within a node I am trying to do this


Not getting any value am i correct ?

First, you have to be careful that Diagram.findNodeForKey actually returns an instance of a Node, not null if the key is not present in the model.

Second, “lists”, “links”, and “element” are not properties of the Node class. Node | GoJS API
Try to use only documented properties and methods of the GoJS classes.

Now I made some progress , I see that they made a template like below.

main Panel

Sub panel Shapes ?

For every new node it has click object … So if there are 5 nodes, then there are 5 templates like this added. This has this below code. Now thing is this one is below the nodes ? Now the Panel does not come under according to gojs, panel is on top of node. so i cant find a node and find these panels below them can I ?. How to find these objects ?

$(go.Shape, 'zzzzz',

Lets say thie code is this

              $(go.Shape, 'zzzzz',
                {fill: '....', height: .., width: .., stroke: null, margin: new go.Margin(0, .., .., 0)}

can they name it ? and I can find these object using named value ?

If the template had given that “Circle” Shape a, say “CIRCLE”, then you could have found it at run-time by calling node.findObject("CIRCLE")

But it doesn’t have a, so you need to traverse the visual tree of the node and find that shape. If you always know exactly how to get there from the node, you could hard-code it by calling Panel.elt. But that does make it susceptible to changes in the node template in future versions of your software.

go.Diagram.fromDiv(‘id’).findNodeForKey(1).findObject(‘Named_Object’) …
did not get me any data

though under each node ? … this thing is here

$(go.Shape, 'zzzzz',
                {fill: '....', height: .., width: .., stroke: null, margin: new go.Margin(0, .., .., 0)}

As I said, that node template does not have a name on that Shape. You would want something like:

$(go.Shape, "Circle",
  { name: "CIRCLE", height: 3, . . . })

:) Really thanks Walter makes life very very easy for lot of people …[I modified code to introduce name]

QQ how can i get co ordinates now ? i used model to initially do same … but now drilling down to specific object … as a node ? using above how to get x and y

You can call GraphObject.getDocumentPoint or GraphObject.getDocumentBounds to get back a Point or a Rect in document coordinates.

Thanks @walter

@DeepaPatri - Would you mind to share how did you resolve Error : Circular Reference?

I tried following but no luck :

((JavascriptExecutor) driver).executeScript(“return JSON.parse(JSON.stringify(document.getElementsByClassName(‘myDiagramDiv’)[0].goDiagram));”);