Search code examples
javascripttestingjscripttestcomplete

Get data from XML - jscript - TESTCOMPLETE


I have problem. I need change this value="0,20" to value="1,20" in

<configuration>
<deviceConfiguration>
<devices>

<add logicalName="MainScale" type="XXX.XXX.XXX.XXX.XXX, XXX.XXX.XXX">
    <parameters>
        <add key="CustomWeight" value="0,20"/>
    </parameters>
</add>

</devices>
</deviceConfiguration>
</configuration>

How can i get this value? Thank you so much for help!!!


Solution

  • You can find information on how to work with XML files in a TestComplete script in the Working With XML Files From Scripts help topic. Here is a specific sample code that should work for your case:

    function test()
    {
      var doc = getActiveXObject("Msxml2.DOMDocument.6.0");
      doc.async = false;
      doc.load("d:\\test.xml");
    
      var node = doc.selectSingleNode("//devices/add/parameters/add[@key='CustomWeight']");
      Log.Message("Old value: " + node.getAttribute("value"));
      node.setAttribute("value", "1,20");
      Log.Message("New value: " + node.getAttribute("value"));
    
      doc.save("d:\\test_updated.xml");
    }