Select Canvas 节点使用 go.Diagram

Select Canvas Node using go.Diagram

我可以点击所需的 canvas 节点,但还需要 select 该节点,然后才能点击附加到它的“+”按钮

//get a reference to the diagram object
const diagram = go.Diagram.fromDiv(document.getElementsByClassName("diagram-component")[0])
    
//using the diagram object find a node by name
const node = diagram.findNodesByExample({text: "capeutil"}).first()
    
//once you have the node you can expand it with the following command
node.findObject('ButtonButton').click(null, {part:node});

需要帮助 select 文本节点

Selenium 实现

public void test_node_selection(String nodeName){
        sleep(5);
        JavascriptExecutor js = (JavascriptExecutor) context.getDriver();
        js.executeScript(
                "const diagram = go.Diagram.fromDiv(document.getElementsByClassName('diagram-component')[0]);" +
                        "const node = diagram.findNodesByExample({text: '" + nodeName + "'}).first()" +
                        "diagram.select(node);");
    }

如果您有一个节点的引用,您可以通过调用 Diagram.select

select 它
diagram.select(node);

请注意,这会清除图表可能具有的任何其他 selection。