We can find Xpath for given node in XML file using with below two functions.
First function:--
Call ExtractProductCode
Function ExtractProductCode
Environment.Value("columnExcel")=3
Set doc = XMLUtil.CreateXML()
doc.LoadFile "C:\FileName.xml"
Set root = doc.GetRootElement
Environment.Value("ParentName") = root.ElementName()
'Set children = root.ChildElements()
'Msgbox children.Count()
call XMLDataExtract1(root.ChildElements(), root.ChildElements().Count())
End Function
Function XMLDataExtract1(children, cnt)
c1= children.Count()
If cnt > 0 Then
For i= 1 to cnt 'children.Count()
Set firstChild = children.Item(i)
c2 = firstChild.ElementName()
c3 = firstChild.Value()
If Trim(CStr(c2)) = Trim(DataTable.Value("NodeName","Global")) Then '
XMLPath= ""
While firstChild.ElementName() <>"soapenv:Envelope"
XMLPath= "/" & CStr(firstChild.ElementName()) & XMLPath
Set firstChild= firstChild.Parent()
Wend
XMLPath = "/" & Environment.Value("ParentName") & XMLPath
DataTable.Value(cInt(Environment.Value("columnExcel")),"Global") = XMLPath
Environment.Value("columnExcel")= cInt(Environment.Value("columnExcel"))+1
Exit Function
End If
If firstChild.ChildElements().Count() > 0 Then
Set children = firstChild.ChildElements()
call XMLDataExtract1(children,children.Count())
End if
Next
End If
Reporter.Filter = 3
'MsgBox firstChild.Parent().Parent().ElementName()
On Error Resume Next
Set children = firstChild.Parent().Parent().ChildElements()
On Error Goto 0
Reporter.Filter = 0
End Function
Friday, October 15, 2010
Friday, June 25, 2010
How to Use Dictionary Object in QTP?
Simple Code example for Dictionary object:-
Dim objDict 'Create a variable
Set objDict = CreateObject("Scripting.Dictionary")
objDict.Add "Name", "SP" 'Add some keys and items
objDict.Add "Address", "Street1"
objDict.Add "City", "Bangalore"
objDict.Add "State","Karnataka"
objDict.Add "Country","India"
For Each I in objDict
msgbox objDict.Item(I)
Next
Please find the infromation in the below.
http://www.learnqtp.com/dictionary-object-qtp-use/
Dim objDict 'Create a variable
Set objDict = CreateObject("Scripting.Dictionary")
objDict.Add "Name", "SP" 'Add some keys and items
objDict.Add "Address", "Street1"
objDict.Add "City", "Bangalore"
objDict.Add "State","Karnataka"
objDict.Add "Country","India"
For Each I in objDict
msgbox objDict.Item(I)
Next
Please find the infromation in the below.
http://www.learnqtp.com/dictionary-object-qtp-use/
Labels:
General
Tuesday, June 22, 2010
Unlock QTP Script Which is Locked in Quality Center
Any script is locked in QC By other user, we can unlock script with below code.
Set QCConnection=QCUtil.QCConnection
Set con=QCConnection.command
con.CommandText="DELETE FROM LOCKS WHERE LK_USER ='QC User ID'" Set recset=con.execute
Set QCConnection=QCUtil.QCConnection
Set con=QCConnection.command
con.CommandText="DELETE FROM LOCKS WHERE LK_USER ='QC User ID'" Set recset=con.execute
Labels:
QC Automation
Thursday, May 27, 2010
Enter values in specified Node in XML file
Enter the data in specified Node in XML file with below code.
Code :-
Set Doc = XMLUtil.CreateXML()
Doc.LoadFile "XmlFilePath"
Set root = doc.GetRootElement()
Set children = root.ChildElements()
For i = 1 to datatable.LocalSheet.GetRowCount
datatable.LocalSheet.SetCurrentRow(i)
Set firstChild = doc.GetRootElement().ChildElementsByPath("Node path through Local sheet").Item(1)
firstChild.setValue "Enter Value"
Next
doc.SaveFile "C:\Test_SaveAs.XML"
Code :-
Set Doc = XMLUtil.CreateXML()
Doc.LoadFile "XmlFilePath"
Set root = doc.GetRootElement()
Set children = root.ChildElements()
For i = 1 to datatable.LocalSheet.GetRowCount
datatable.LocalSheet.SetCurrentRow(i)
Set firstChild = doc.GetRootElement().ChildElementsByPath("Node path through Local sheet").Item(1)
firstChild.setValue "Enter Value"
Next
doc.SaveFile "C:\Test_SaveAs.XML"
Labels:
XML Automation
Friday, May 7, 2010
Get the Numeric value from a Alpha Numeric String
Get the Numeric value from a string which is containing numeric and string combinations with below code :-
strValue="DNT -1,21,21,123.99 value generated"
ActValue = ""
intStringLength = Len(strValue)
For intPos = 1 TO intStringLength
If IsNumeric(Mid(strValue,intPos,1)) Then
ActValue = ActValue & Mid(strValue,intPos,1)Else
If Mid(strValue,intPos,1) = "." Then
ActValue = ActValue & Mid(strValue,intPos,1) End If
End If
Next
strValue="DNT -1,21,21,123.99 value generated"
ActValue = ""
intStringLength = Len(strValue)
For intPos = 1 TO intStringLength
If IsNumeric(Mid(strValue,intPos,1)) Then
ActValue = ActValue & Mid(strValue,intPos,1)Else
If Mid(strValue,intPos,1) = "." Then
ActValue = ActValue & Mid(strValue,intPos,1) End If
End If
Next
Labels:
General
Subscribe to:
Posts (Atom)