Updating Second Child Element
Below is the Code I am using to setup 2 child nodes Selection of Selections- I need to updated the second child node/Element with a New ID and order Number - I have tried to use XmlUtils.getChildElement(parentNode, "Selection") But not sure what to enter in the () or how I can get the second Child Element to update
def reqHolder = groovyUtils.getXmlHolder( "$teststepname#Request" )
parentNode = reqHolder.getDomNode("//Selections")
XmlUtils.addChildElement(parentNode, "Selection", "")
reqHolder.updateProperty()
parentNode = reqHolder.getDomNode("//Selections")
XmlUtils.addChildElement(parentNode, "Selection", "")
reqHolder.updateProperty(
//*****Adding attributes***** (In this case, adding an attribute active="true" to the number element
parentNode = reqHolder.getDomNode("//Selection")
parentNode.setAttribute("id", '${#Project#WRunner}')
parentNode.setAttribute("order", "1")
reqHolder.updateProperty()
Found the answer put in [] after the element and the number of the node/element you are after
So parentNode = reqHolder.getDomNode("//Selection") will become parentNode = reqHolder.getDomNode("//Selection[1]") to update the first element/Node and ("//Selection[2]") for the second
parentNode = reqHolder.getDomNode("//Selection[1]")
parentNode.setAttribute("id", '${#Project#WRunner1}')
parentNode.setAttribute("order", "1")
reqHolder.updateProperty()parentNode = reqHolder.getDomNode("//Selection[2]")
parentNode.setAttribute("id", '${#Project#WRunner2}')
parentNode.setAttribute("order", "2")
reqHolder.updateProperty()