UI Automation: Click event on selection of a link

Hi All,

We are using Go.JS in our project and we were trying to automate it with Selenium.
So far we are successfully able to play with the nodes, and also able to link two node with the help of Robot class in JavaScript.

Now we are stuck at a point and not able to find any solution.
The problem is we want to click on the link connecting the 2 nodes.

image

In case of nodes, with the help of document.getElementsByClassName(‘gojs-diagram-div’)[0].goDiagram.model.nodeDataArray would return a collection of all the objects within the diagram, so in this case we can use “Location” attribute to trigger mouse up and down events.

But in case of link we don’t have location or any such attribute present.
image

So far we are able to locate the link and also select it, but not able to trigger mouse up and down event to click on it.

Any help would be greatly appreciated.
Thanks in advance

Rohit Goud

I have a couple suggestions:

  1. Instead of using the model arrays, use the actual diagram collections – Diagram.nodes and Diagram.links – or Diagram.findNodeForKey/findLinkForKey. Unless you actually need the data for your testing…
  2. To trigger events, I’d recommend:
// nodes
const pt = myNode.getDocumentPoint(go.Spot.Center);
... trigger mouseUp/mouseDown, etc. ...
// links
const path = myLink.path;
const pt = path.getDocumentPoint(path.geometry.getPointAlongPath(.5));
... trigger mouseUp/mouseDown, etc. ...

Hi Jhardy,

First of all thank you for the quick reply,

the solution you suggested where path is used, I have a small question here is this path any user defined attribute or GO JS attribute ?
Because in our case we don’t have any path attribute, pls refer ss for reference

with document.getElementsByClassName(‘gojs-diagram-div’)[0].goDiagram.model.findLinkDataForKey(lindID), we are able to get point attribute but that returns null value.

Yes, it’s an element of a Link. That’s why I recommended getting the links via Diagram.links or Diagram.findLinkForKey instead of using the link data.

By using the document.getElementsByClassName(‘gojs-diagram-div’)[0].goDiagram.findLinkForKey(“linkID”).geometry.getPointAlongPath(0.5) I am getting the x and y points, but it seems to be incorrect, for instance, the 2 nodes linked both has y as 100, but we are getting y value as 0 by using above method.

Also I am trying to fetch the value but its returning null value.

The points of a Geometry are always in the Shape’s local coordinate system. So every Link whose Link.path is a straight horizontal line will have a Geometry whose points have y values that are zero no matter where the Link is in in the document or in the viewport.

Input events are always in document coordinates. If you want to click on a Link.path Shape you need to convert a Shape.geometry point from its local coordinates to document coordinates. That is why the code we gave you, above, called GraphObject.getDocumentPoint on the Shape.

const pt = path.getDocumentPoint(path.geometry.getPointAlongPath(.5));