Wednesday, 19 June 2013

XML File Parsing

XML File Parsing - Generic - VB code

Objective : Parse the XML to get all the nodes of any XML file .

First get the root node of the XML using oXml.documentElement.
Then check whether that root node has child nodes and do it repeatedly for all the nodes until its the last node.
The above can be achieved easily using recursion.

Belwo code can be used to parse any XML - To get all the nodes of XML

PS: The code is in VB but the same approach can be used for other languages and can be customized.

**************Code******************************

' Declare the variables
Dim oXml As DOMDocument
Dim oRoot As IXMLDOMNode
Dim Childnode As IXMLDOMNode

Sub ParseXml()

'Load the xml File
 Set oXml = CreateObject("Msxml2.DOMDocument")
 oXml.async = True
 xmlFile = ReadXMLfile(AnyFileLocation)
 oXml.loadXML xmlFile

'Set the root of the XML
Set oRoot = oXml.documentElement

'Call Recursive function and pass the root node of the XML
Call getChildNodes(oRoot)

End Sub

'Recursive function
Function getChildNodes(curNode As IXMLDOMNode)

'Çheck if the node has child nodes
If curNode.hasChildNodes = True Then
   For Each Childnode In curNode.childNodes
  
    'If yes then again call the recursive function

   Call getChildNodes(Childnode)
   Next
  
Else

   'If not then its doesnt have any more child nodes and we can print the node
   MsgBox curNode.nodeName

End Function


Friday, 24 May 2013

Selenium IDE- Capture ScreenShot

Selenium IDE- Capture Screen

In Selenium IDE,below command can be used to take screens shots and save in particular location.

Command: captureEntirePageScreenshot

Target :  D:\Ia2tech.png

Driectory will not be created if they don't exist and an exception will be thrown.



 

Selenium - Adding User Extensions

Selenium - Adding User Extensions

Parametrization and looping is not supported in Selenium IDE so for that user extensions(.js) files can be loaded in Selenium as below :

Go to Options -> Options -> Selenium Core extensions -> Browse and load the .js files from your local machine.