WORKING WITH QTP

TestEveryThinG

Archive for April, 2009

Select Radio Button QTP

Posted by rajivkumarnandvani on April 29, 2009

Rem**************************************************************************************


Rem This function select the radio button with specified number of index
REM  Input objRadiobutton:= radiobutton object intenetexplorer exe || nIndex:= number of specifed radio button which need to be   rem select
REM  Output(ReturnType) := None
REM  Created:    07/April/2009    Rajiv Kumar Nandvani  ##
REM Changed:MM/DD/YYYY

REM***************************************************************************

Public Function fn_RadioButtonSelect( byref  objRadiobutton,byval nIndex)

sItems= objRadiobutton.GetROProperty(“all items”)
sItems=split(sItems,”;”)
nIndex =nIndex-1

If  nIndex =< (ubound(sItems) ) Then
objRadiobutton.select sItems(nIndex)
else
Print  “Please check  number of radio button”

End If

Rem  Clear All  the Refrences to the Objects
Set objRadiobutton =nothing
End Function

Posted in QTP | Tagged: , , | 1 Comment »

Get EXCEL COLUMN VB / in Array

Posted by rajivkumarnandvani on April 25, 2009

sXLpath =”C:\TESTXML\Rajiv.xls”
myArray = GetALLColumn(sXLpath)

Public function GetALLColumn(Byval  xlFilePath  )
rem define array column
Dim AllColumn()
Set ObjAppExcel = CreateObject(“Excel.Application”)
rem Disable alerts
ObjAppExcel.DisplayAlerts = False
rem Add a workbook to the Excel App
ObjAppExcel.Workbooks.open(xlFilePath)
‘Get the object of the first sheet in the workbook
Set objectSheet = ObjAppExcel.Sheets(“Sheet1”)
rem count used Column in sheet
nColumnCount =objectSheet.UsedRange.Columns.Count

ReDim  preserve AllColumn(nColumnCount-1)
For i=0 to nColumnCount-1
AllColumn(i) =objectSheet.Cells(1,i+1).value

Next

GetALLColumn =AllColumn
Set objectSheet =nothing
Set ObjAppExcel =nothing
End Function

Posted in QTP | Tagged: , , , | 1 Comment »

FIND CELL Value in EXCEL VB

Posted by rajivkumarnandvani on April 25, 2009

Some Time we have to Check that particular Cell Value Exist or Not and required the Cell address
rem this function return the first  find Cell address  value of your Excel sheet  & Change Color of Cell find value
rem input parameter xlFilePath := xls file path || FindValue =value which need to be find

dim sXLpath , FindValue ,getCellAddress
sXLpath =”C:\RajivKumarNandvani.xls” rem define xls file path
FindValue =”Rajiv” rem check rajiv in cell exist or not
getCellAddress = FindCellAddress(sXLpath ,FindValue )
msgbox getCellAddress

Public function  FindCellAddress(Byval  xlFilePath ,byval FindValue )

Set ObjAppExcel = CreateObject(“Excel.Application”)
rem Disable alerts
ObjAppExcel.DisplayAlerts = False
r
em Add a workbook to the Excel App
ObjAppExcel.Workbooks.open(xlFilePath)
REm Get the object of the first sheet in the workbook
Set objectSheet = ObjAppExcel.Sheets(“Sheet1”)
rem define the range from A1 to last column address and filnd the value in range
set objValueFind = objectSheet.UsedRange.Find(FindValue)
If not objValueFind is nothing Then
CellAddress =objValueFind.address
FindCellAddress=replace(objValueFind.address,”$”,””)
FindCellAddress=replace( FindCellAddress,”1″,””)

Do

set objValueFind = objectSheet.UsedRange.FindNext(objValueFind )

Loop While Not objValueFind Is Nothing And objValueFind.Address <> CellAddress

Exit function

End If
rem if not found then return the Empty
FindCellAddress=”NOT FOUND”

Set objValueFind =nothing
Set objectSheet =nothing
Set ObjAppExcel =nothing
End Function

Posted in Miscellaneous, QTP | Tagged: , , , , | 3 Comments »

Get Column Address Excel VB / Find Column

Posted by rajivkumarnandvani on April 25, 2009

Some Time we have to Check that particular column Exist or Not abd required the column address
rem this function return the column address of your Excel sheet
rem input parameter xlFilePath := xls file path || FindColumn =column value which need to be check

dim sXLpath , FindColumn ,getColumnAddress
sXLpath =”C:\RajivKumarNandvani.xls” rem define xls file path
FindColumn =”Rajiv” rem check rajiv in column exist or not
getColumnAddress = FindColumnAddress(sXLpath ,FindColumn )
msgbox getColumnAddress
Public function FindColumnAddress(Byval xlFilePath ,byval FindColumn )

Set ObjAppExcel = CreateObject(“Excel.Application”)
rem Disable alerts
ObjAppExcel.DisplayAlerts = False
rem Add a workbook to the Excel App
ObjAppExcel.Workbooks.open(xlFilePath)
‘Get the object of the first sheet in the workbook
Set objectSheet = ObjAppExcel.Sheets(“Sheet1”)
rem count used Column in sheet
nColumnCount =objectSheet.UsedRange.Columns.Count
rem get the last column address
c =replace(objectSheet.Cells(1,nColumnCount).address,”$”,””)
rem define the range from A1 to last column address and filnd the value in range
set objValueFind = objectSheet.Range(“A1:”&c).Find(FindColumn)
If not objValueFind is nothing Then
FindColumnAddress =replace(objValueFind.address,”$”,””)
FindColumnAddress =replace(FindColumnAddress,”1″,””)
Exit function

End If
rem if not found then return the Empty
FindColumnAddress =”NOT FOUND”

Set objValueFind =nothing
Set objectSheet =nothing
Set ObjAppExcel =nothing
End Function

Posted in Miscellaneous, QTP | Tagged: , , , | Leave a Comment »

Check XML File Valid OR Not VB QTP

Posted by rajivkumarnandvani on April 21, 2009

REM ************************************************
Rem This Function Check XML File Valid OR not  if  File not valid XML  then return False  Else  True
REM  Function  fn_CheckXMLValid(  sXMLfilepath)
REM  Input sXMLfilepath := XMLfilepath
REM  Output(ReturnType) := True or False
REM  Created:    21/April/2009    Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY

REM *************************************************************************

Public Function    fn_CheckXMLValid(byval sXMLfilepath)
rem create XML object
Set xmlDoc = CreateObject( “Microsoft.XMLDOM” )
xmlDoc.Async = “False”
Rem load XML File
xmlDoc.Load( sXMLfilepath )
If  xmlDoc.parseError.errorCode<>0 Then
fn_CheckXMLValid=False
else
fn_CheckXMLValid=True
End If
Set xmlDoc = nothing

End Function

REM ************************************************

Posted in QTP | Tagged: , , , | Leave a Comment »

Get current DATETIME through VB QTP/Create unique file or folder

Posted by rajivkumarnandvani on April 17, 2009

Some Time we want create a folder Or File with unique name then we current date time value for creating the file or folder that we can use this method for create the file OR folder as decribed here

REM this function return the current date time in text format

REM  Function  fn_GetDateTimeText() This function return currentdatetime in Text format
REM  this will remove the specail charactor from currentdatetime & replace with _ underscore
REM  Input              := None
REM  Output(ReturnType) := return currentdatetime in Text format

Public Function fn_GetDateTimeText

Dim sDateTime
sDateTime = now
sDateTime =replace(sDateTime,”:”,”_”)
sDateTime =replace(sDateTime,”>”,”_”)
sDateTime =replace(sDateTime,”<“,”_”)
sDateTime =replace(sDateTime,”/”,”_”)
sDateTime =replace(sDateTime,”|”,”_”)
sDateTime =replace(sDateTime,”\”,”_”)
sDateTime =replace(sDateTime,”*”,”_”)
sDateTime =replace(sDateTime,””””,”_”)
sDateTime =replace(sDateTime,”#”,””)
fn_GetDateTimeText =sDateTime
End Function

dim sGetCurrentDateTime

sGetCurrentDateTime = fn_GetDateTimeText()

Set objFSO =CreateObject(“Scripting.FileSystemObject”)

rem create text file

objFSO.CreateTextFile(“c:/” & sGetCurrentDateTime & “.txt” , True)

rem create folder

objFSO.CreateFolder(“c:/” & sGetCurrentDateTime & “.txt” , True)

Posted in QTP, WINDOWS | Tagged: , , , , , , | 1 Comment »

Delete Cookies and Temprary internet files VB QTP

Posted by rajivkumarnandvani on April 17, 2009

rem ********************************

rem delete cookies

call fn_DeletesubFolderAndFiles(“C:\DOCUME~1\%USERNAME%\Cookies”)

rem *********************************

rem rem delete Temporary internet files

call fn_DeletesubFolderAndFiles(“C:\DOCUME~1\%USERNAME%\Locals~1\Tempor~1”)

rem ***********************************

REM *************************************************************************

REM Function fn_DeletesubFolderAndFiles(path)

Rem this Function delete the files & subfolder under the specified path

REM Input spath := Files path or parent Folder path

REM Output(ReturnType) := None

REM Note := IF file Protected then it will not delete without giving Error

REM Created: 17/April/2009 Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY

REM *************************************************************************

Public Function fn_DeletesubFolderAndFiles(spath)

on Error Resume Next

rem Create File System object

set objFileSystem = CreateObject(“Scripting.FileSystemObject“)

rem Create Window Shel object

Set objWshShell = CreateObject(WScript.Shell“)

Rem get Folderpath under which file present

Set objoFolder = objFileSystem.GetFolder(objWshShell.ExpandEnvironmentStrings(spath))

rem get count the files under the folder and loop run for delete the files

For Each oFile In objoFolder.files

On Error Resume Next

objFileSystem.DeleteFile oFile

Err.clear

Next

rem get count the subfolders under the folder and loop run for delete the subfolders

For Each oSubFolder In objoFolder.SubFolders

On Error Resume Next

objFileSystem.DeleteFolder oSubFolder

Err.clear

Next

rem clear the object

set objFileSystem = nothing

set objWshShell = nothing

set objoFolder = nothing

Err.clear

End function

Posted in QTP, WEB | Tagged: , , , , , | Leave a Comment »

Handle popup window QTP VB

Posted by rajivkumarnandvani on April 11, 2009

REM *************************************************************************
REM  Function  fn_GetPopupMessageText() This function Get the lable textmessage from Popup Dialog window  in Browser page
REM  and enter the label text in Result Excel Sheet
REM Note Dialog Window Must be child of  Parent object

REM  Input              := None
REM  Output(ReturnType) := None
REM  Created:    11/April/2009    Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY

REM *************************************************************************

Call fn_GetPopupMessageText()
Public function fn_GetPopupMessageText()
Set objStaticText =Description.Create()
objStaticText(“nativeclass”).value =”Static”
objStaticText(“text”).value =”.*[a-z].*”
Set objWinbutton =Description.Create()
objWinbutton(“micclass”).value =”WinButton”
If Window(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=IEFrame”).Dialog(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=#32770″).Exist(2) then
Window(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=IEFrame”).Dialog(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=#32770″).Activate
set objStaticText = Window(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=IEFrame”).Dialog(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=#32770″).ChildObjects(objStaticText)
For i=0 to objStaticText.count-1
sDescription =objStaticText(i).GetVisibleText(-1,-1,-1,-1)
Next
set objWinbutton = Window(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=IEFrame”).Dialog(“regexpwndtitle:=Windows Internet Explorer”,”regexpwndclass:=#32770″).ChildObjects(objWinbutton)
For i=0 to objWinbutton.count-1
objWinbutton(i).click
Exit for
Next
fn_GetPopupMessageText = sDescription
End if
End Function

Public function fn_GetPopupMessageText()
Set objStaticText =Description.Create()
objStaticText(“nativeclass”).value =”Static”
objStaticText(“text”).value =”.*[a-z].*”
Set objWinbutton =Description.Create()
objWinbutton(“micclass”).value =”WinButton”
If Browser(“title:=.*(Page).*”).Dialog(“text:=Windows Internet Explorer”,”nativeclass:=#32770″).Exist(2) then
Browser(“title:=.*(Page).*”).Dialog(“text:=Windows Internet Explorer”,”nativeclass:=#32770″).Activate
set objStaticText = Browser(“title:=.*(Page).*”).Dialog(“text:=Windows Internet Explorer”,”nativeclass:=#32770″).ChildObjects(objStaticText)
For i=0 to objStaticText.count-1
sDescription =objStaticText(i).GetVisibleText(-1,-1,-1,-1)
Next
set objWinbutton = Browser(“title:=.*(Page).*”).Dialog(“text:=Windows Internet Explorer”,”nativeclass:=#32770″).ChildObjects(objWinbutton)
For i=0 to objWinbutton.count-1
objWinbutton(i).click
Exit for
Next

fn_GetPopupMessageText = sDescription
End if

End Function

Posted in QTP, WEB, WINDOWS | Tagged: , | 1 Comment »

XML WITH VB

Posted by rajivkumarnandvani on April 10, 2009

sXMLfilepath =”C:\ReadXML.xml”

strQuery = “/ProfilesInfo/Profiles/ProfileInfo/Profile/Fields/Field [Name=’ProfileUri’ or  Name= ‘Age’] /(Name|Value)”

call ReadXMLValueFromStringQuery( sXMLfilepath ,strQuery)

Public Function       ReadXMLValueFromStringQuery(byval sXMLfilepath , byval strQuery)

Set xmlDoc = CreateObject( “Microsoft.XMLDOM” )
xmlDoc.Async = “False”
xmlDoc.Load( sXMLfilepath )
If  xmlDoc.parseError.errorCode<>0 Then
Print “Invalid XMLFile/No file ”
else
‘strQuery = “/ProfilesInfo/Profiles/ProfileInfo/Profile/Fields/Field [Name=’ProfileUri’ or  Name= ‘Age’] /(Name|Value)”
Set colNodes = xmlDoc.selectNodes( strQuery )
If colNodes.length>0 Then
For Each objNode in colNodes
Print  objNode.nodeName & “: ” & objNode.text
Next
else
Print “Nothing Found for this strQuery  =” & strQuery
End If
End If
Set  xmlDoc = nothing
Set  colNodes = nothing
End Function
Set xmlDoc =nothing

Set ElemList =nothing

Set xmlDoc = CreateObject(“Msxml2.DOMDocument”)

xmlDoc.load(“C:\TestData.xml”)

Set ElemList1= xmlDoc.DocumentElement.ChildNodes

For i = 0 to ElemList1.length-1

msgbox ElemList1.item(i).text

next

Set ElemList = xmlDoc.getElementsByTagName(“book”)

filepath = ElemList.item(0).getAttribute(“author”)

MsgBox filepath

Set ElemList = xmlDoc.getElementsByTagName(“title”)

plot = ElemList.item(0).Text

MsgBox plot

Let’s get started.

In your editor, IDE or whatever, type the following code:

Set xmlDoc = CreateObject( "Microsoft.XMLDOM" )
xmlDoc.Async = "False"
xmlDoc.Load( "dvdcoll.xml" )

If you have an integrated object browser, you’ll probably see a reference to MSXML being inserted.

We’ll start with simple query, display each DVD’s title:

strQuery = "/Collection/DVD/Title"
Set colNodes = xmlDoc.selectNodes( strQuery )
For Each objNode in colNodes
	WScript.Echo objNode.nodeName & ": " & objNode.text
Next

The result will look like this:

Title: Wild Down Under
Title: Pride
Title: Gandhi
Title: The Abyss
Title: Shouf Shouf Habibi

So, why was the query built like this?

<!-- DVD Profiler Version 2.4.0 Collection Export --> <!-- Exported: 22-02-2007 20:13:12 --> <Collection> <DVD>   <ID>014503132125.4</ID>   <UPC>014503-132125</UPC>   <ProfileTimestamp>2006-10-29 10:38:45</ProfileTimestamp>   <Title>Wild Down Under</Title>   <SortTitle>Wild Down Under</SortTitle>

Take a look at the image on the right, a fragment of a screenshot of XML Notepad’s “XSL Output” window with our XML file loaded (or open the XML file in a plain text editor).

What we see is an opening tag <Collection> as the first tag. This translates to /Collection in the query.

Then, between the opening <Collection> and closing </Collection> tags (“inside” the Collection), note the “recordsets” of <DVD> and </DVD> tags. These translate to the DVD part of the query: in the root we find Collections, and inside (or under) Collections we find DVD — just like a directory structure on a disk.

Inside (or under) DVD there are several tags, Title being one of them. So now we have /Collection/DVD/Title.

Note: Queries are case sensitive! Capitalization must match the XML tags exactly.

Now let’s move to the next level of complexity for our queries, display multiple properties:

strQuery = "/Collection/DVD/ ( Title | Genres )"
Note: This is the query definition only. Replace the previous query definition by this new one. The rest of the script remains unaltered.

The part of the query between parentheses is a list of choices, separated by “pipe” characters (|).

Tags will be listed if they match any of these choices, so Title as well as Genres will be shown for each DVD in the collection.

The result will look like this:

Title: Wild Down Under
Genres: Documentary Special Interest
Title: Pride
Genres: Documentary
Title: Gandhi
Genres: Drama Classic
Title: The Abyss
Genres: Science-Fiction Suspense/Thriller
Title: Shouf Shouf Habibi
Genres: Comedy

The genres are listed as single lines, where each line can contain one (or zero) or more genres.

If you look further down in the XML structure, you’ll notice that some keys or tags have subkeys: Genres for example uses Genre subkeys.

Subkeys are used when multiple values are possible. They can be viewed best in XML Notepad’s treeview.

To list each individual genre we must use /Collection/DVD/Genres/Genre.

So next, let’s display the Title and each individual Genre:

strQuery = "/Collection/DVD/ ( Title | Genres/Genre )"

Roughly translated: display anything that matches "/Collection/DVD/Title" or "/Collection/DVD/Genres/Genre"

The result will look like this:

Title: Wild Down Under
Genre: Documentary
Genre: Special Interest
Title: Pride
Genre: Documentary
Title: Gandhi
Genre: Drama
Genre: Classic
Title: The Abyss
Genre: Science-Fiction
Genre: Suspense/Thriller
Title: Shouf Shouf Habibi
Genre: Comedy

Notice how some DVDs have multiple Genres.

OK, listing properties for each item in a collection no longer has any secrets for you.

Let’s select specific items (DVDs) from the collection.

List the titles and genres of all documentaries:

strQuery = "/Collection/DVD [ Genres/Genre = 'Documentary' ] / ( Title | Genres/Genre )"

The result will look like this:

Title: Wild Down Under
Genre: Documentary
Genre: Special Interest
Title: Pride
Genre: Documentary
Title: March of the Penguins
Genre: Documentary
Title: Alaska: Spirit of the Wild
Genre: Documentary
Genre: Special Interest
Title: Wilderness Journey - Canyon Suites
Genre: Documentary
Genre: Special Interest
Genre: Music

It is possible to select based on genre without displaying it:

strQuery = "/Collection/DVD [ Genres/Genre = 'Documentary' ] /Title"

would only display the titles of the documentaries.

Finally, the selection can be narrowed down by using and and or. Note that these are case sensitive, so And will not work.

List titles and all formats for each documentary that supports 16×9 format:

strQuery = "/Collection/DVD " _
         & "[ Genres/Genre = 'Documentary' and Format/Format16X9 = 'True' ] " _
         & "/ ( Title | Format/* )"

The result will look like this:

Title: Wild Down Under
FormatAspectRatio: 1.78
FormatVideoStandard: PAL
FormatLetterBox: True
FormatPanAndScan: False
FormatFullFrame: False
Format16X9: True
FormatDualSided: False
FormatDualLayered: False
FormatFlipper: False
Title: Pride
FormatVideoStandard: PAL
FormatLetterBox: True
FormatPanAndScan: False
FormatFullFrame: True
Format16X9: True
FormatDualSided: False
FormatDualLayered: True
FormatFlipper: False

Posted in QTP, WEB | Tagged: | Leave a Comment »

WEB Tree Control VB script QTP

Posted by rajivkumarnandvani on April 8, 2009

REM *************************************************************************
REM  Function  Click the Tree Node link  as per given Node name
REM  Input    objPage          := Paranet object  eg. webpage
REM  Input    ElementId          :=  Tree Control Web Element ID  (html id  value)   e.g  “ctl00_contRMSMaster_ucConnectionBasicInfo_trvwPopulateTree”
REM  Input    sName          := Name of the link But alway s give  the value in heriachy manner  by seprated comma  like “Utility,India,Hayana”
rem if  your Tree Stucture is Like This  Utility–>India–>Hayana or  Utility–>India–>Delhi
rem for click  India give the value  like This  sName =”Utility,India”
rem for click  Hayana  give the value  like This  sName =”Utility,India,Hayana”   not  alone Hayana always give the value from Root node in herarchy manner
REM  Input    nWaitTime          := time ( second)  for expand the tree control because On expand page get refresh  if  your page Get refresh on expand give the value as per refresh Time  Or If Page does not get refresh then give the minimum value
REM  Output(ReturnType) := return  none
REM  used functions are  fn_ExpandTree
REM  Created:    13/Mrach/2009    Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY
REM  Example  fn_ClickTreeNode (objPageRMS ,”ctl00_contRMSMaster_ucConnectionBasicInfo_trvwPopulateTree”,”Utility,India” ,5 )

REM *************************************************************************

Public function fn_ClickTreeNode (byval objPage,byval ElementId ,byval sName ,byval nWaitTime )
rem store the all given node name in Array  seprated by comma using Split method
sGaahire =split(sName,”,”)
rem Run the Loop for  by counting  all given node name in Array
For i=0 to ubound(sGaahire)
rem call  function  fn_ExpandTree for  check Node name Exist or not  if Exist  and expandable  then expand the node
blCheck =   fn_ExpandTree( objPage, ElementId , trim(sGaahire(i)),nWaitTime)
rem check the array  sGaahire  last  value because last node value  we have to Click  (e.g  “Utility,India”  India will be last node )
If blCheck = True and i= ubound(sGaahire) Then
rem Call function  fn_clickTreelink for click the Last node Value
call   fn_clickTreelink(  objPage, ElementId , trim(sGaahire(i)))
End If
Next
Rem  Clear All  the Refrences to the Objects
Set  objPage = nothing
Set  objDiv = nothing
Set  sMatchName = nothing
Set objchildNodes =nothing
Set sMatchName =nothing
Set objTD =nothing
Set objIMG =nothing

End Function

REM *************************************************************************
REM  Function  Check  given  Tree Node exist  or Not
REM  Input    objPage          := Paranet object  eg. webpage
REM  Input    ElementId          :=  Tree Control Web Element ID  (html id  value)   e.g  “ctl00_contRMSMaster_ucConnectionBasicInfo_trvwPopulateTree”
REM  Input    sName          := Name of the node  But alway s give  the value in heriachy manner  by seprated comma  like “Utility,India,Hayana”
rem if  your Tree Stucture is Like This  Utility–>India–>Hayana or  Utility–>India–>Delhi
rem for Check   India give the value  like This  sName =”Utility,India”
rem for Check  Hayana  give the value  like This  sName =”Utility,India,Hayana”   not  alone Hayana always give the value from Root node in herarchy manner
REM  Input    nWaitTime          := time ( second)  for expand the tree control because On expand page get refresh  if  your page Get refresh on expand give the value as per refresh Time  Or If Page does not get refresh then give the minimum value
REM  Output(ReturnType) := True OR False  if node exist return True  Or False
REM  used functions are  fn_ExpandTree
REM  Created:    15/Mrach/2009    Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY
REM  Example  fn_CheckTreeLinkExist (objPageRMS ,”ctl00_contRMSMaster_ucConnectionBasicInfo_trvwPopulateTree”,”Utility,India” ,5 )

REM *************************************************************************

Public function fn_CheckTreeLinkExist (byval objPage,byval ElementId ,byval sName ,byval nWaitTime )
rem store the all given node name in Array  seprated by comma using Split method
sGaahire =split(sName,”,”)
rem Run the Loop for  by counting  all given node name in Array
For i=0 to ubound(sGaahire)
rem call  function  fn_ExpandTree for  check Node name Exist or not  if Exist  and expandable  then expand the node
blCheck =   fn_ExpandTree( objPage, ElementId , trim(sGaahire(i)),nWaitTime)
rem return value to Function
fn_CheckTreeLinkExist =blCheck

Next
Rem  Clear All  the Refrences to the Objects
Set  objPage = nothing
Set  objDiv = nothing
Set  sMatchName = nothing
Set objchildNodes =nothing
Set sMatchName =nothing
Set objTD =nothing
Set objIMG =nothing

End Function

REM *************************************************************************

REM *************************************************************************
REM  Function  Check  given  check Node name Exist or not  if Exist  and expandable  then expand the node
REM  Input    objPage          := Paranet object  eg. webpage
REM  Input    ElementId          :=  Tree Control Web Element ID  (html id  value)   e.g  “ctl00_contRMSMaster_ucConnectionBasicInfo_trvwPopulateTree”
REM  Input    sName          := Name of the node  But alway s give  the value in heriachy manner  by seprated comma  like “Utility,India,Hayana”
rem if  your Tree Stucture is Like This  Utility–>India–>Hayana or  Utility–>India–>Delhi
rem for Check   India give the value  like This  sName =”Utility,India”
rem for Check  Hayana  give the value  like This  sName =”Utility,India,Hayana”   not  alone Hayana always give the value from Root node in herarchy manner
REM  Input    nWaitTime          := time ( second)  for expand the tree control because On expand page get refresh  if  your page Get refresh on expand give the value as per refresh Time  Or If Page does not get refresh then give the minimum value
REM  Output(ReturnType) := True OR False  if node exist return True  Or False
REM  used functions are   fn_GetDIVid( objPage,ElementId,sName)
REM  Created:    15/Mrach/2009    Rajiv Kumar Nandvani ## Changed:MM/DD/YYYY
REM  Example Call  fn_ExpandTree (objPageRMS ,”ctl00_contRMSMaster_ucConnectionBasicInfo_trvwPopulateTree”,”Utility,India” ,5 )

REM *************************************************************************

Function fn_ExpandTree( byval objPage,byref ElementId ,byval sName ,byval nWaitTime)
rem  set  Div Element
Set objDiv = objPage.Object.getElementById(ElementId)
rem  Set childobject  under  Div Element object
Set objchildNodes =objDiv.children
rem Loop upto   child node  count
For a =0 to objchildNodes.length-1
rem  get  childnode Tagname
sTagName=objchildNodes(a).tagName
If sTagName=”TABLE”  Then
rem set  object  TR Element  under  child node
Set sMatchName =objchildNodes(a).getElementsByTagName(“TR”)
rem Loop upto   sMatchName   count
For p=0 to sMatchName.length-1
rem  check element  innertext  equal to given node name then set  blncheck =1
If sMatchName(p).innerText = sName  Then
blncheck =1
rem set  object  TD  Element  under  element  sMatchName
set objTD = sMatchName(p).getElementsByTagName(“TD”)
If  objTD.length >1 Then
rem set  object  IMG  Element  under  element  sMatchName
set objIMG =  objchildNodes(a).getElementsByTagName(“IMG”)
rem Loop upto   IMG  Element     count
For s =0 to objIMG.length-1
rem get Alt property  value ( tool tip)
sExpand = objIMG(s).alt
rem if node alt proerty value  Expand then Expand the Node
If InStr(1, sExpand, “Expand”, 1) > 0  Then

objIMG(s).parentElement.click
wait(nWaitTime)
rem call function for Next node Div element ID
Call  fn_GetDIVid( objPage,ElementId,sName)
Exit For
End If
If InStr(1, sExpand, “Collapse”, 1) > 0  Then
rem call function for Next node Div element ID
Call  fn_GetDIVid( objPage,ElementId,sName)
Exit For
End If
Next
End If
End If
If blncheck =1 Then
fn_ExpandTree =True
Exit for
else
fn_ExpandTree =False
End If
Next

End If
if   blncheck =1 Then
blncheck=0
Exit for
End If

Next

End Function

Function fn_GetDIVid( byval objPage,byref ElementId ,byval sName)
Set objDiv = objPage.Object.getElementById(ElementId)
Set objchildNodes =objDiv.children
set ObDivLink = objchildNodes
For a =0 to objchildNodes.length-1
sTagName=objchildNodes(a).tagName
If sTagName=”TABLE”  Then
Set sMatchName =objchildNodes(a).getElementsByTagName(“TR”)
For p=0 to sMatchName.length-1
If sMatchName(p).innerText = sName  Then
blncheck =1
Exit for
End If
next
elseif  sTagName=”DIV” and  blncheck =1 Then
ElementId =objchildNodes(a).id
blncheck=0
Exit for
End If

Next
End Function

Function fn_clickTreelink(  byval objPage,byval ElementId ,byval sName)
If objPage.Object.getElementById(ElementId).children.length=1  Then
Set objDiv = objPage.Object.getElementById(ElementId).parentElement
else
Set objDiv = objPage.Object.getElementById(ElementId)
End If
Set objchildNodes =objDiv.children

For a =0 to objchildNodes.length-1
sTagName=objchildNodes(a).tagName
If sTagName=”TABLE”  Then
Set sMatchName =objchildNodes(a).getElementsByTagName(“TR”)
For p=0 to sMatchName.length-1
If sMatchName(p).innerText = sName  Then
set objTD =   sMatchName(p).getElementsByTagName(“TD”)
If  objTD.length >1 Then
set objLink =  sMatchName(p).getElementsByTagName(“A”)
For s =0 to objLink.length-1
sExpand = objLink(s).innerText
If   sExpand= sName Then
objLink(s).click
nExitFlag =1
Exit for
End If
Next
End If
End If
If nExitFlag =1 Then
Exit for
End If
next

End If

If nExitFlag =1 Then
Exit for
End If
If sTagName=”DIV” Then
ElementId = objchildNodes(a).id
call  fn_clickLastlink(  objPage,ElementId ,sName)
Exit for
End If

Next

End Function

Function fn_clickLastlink(  byval objPage,byval ElementId ,byval sName)

Set objDiv = objPage.Object.getElementById(ElementId)
Set objchildNodes =objDiv.children

For a =0 to objchildNodes.length-1
sTagName=objchildNodes(a).tagName
If sTagName=”TABLE”  Then
Set sMatchName =objchildNodes(a).getElementsByTagName(“TR”)
For p=0 to sMatchName.length-1
If sMatchName(p).innerText = sName  Then
set objTD =   sMatchName(p).getElementsByTagName(“TD”)
If  objTD.length >1 Then
set objLink =  sMatchName(p).getElementsByTagName(“A”)
For s =0 to objLink.length-1
sExpand = objLink(s).innerText
If   sExpand= sName Then
objLink(s).click
nExitFlag =1
Exit for
End If
Next
End If
End If
If nExitFlag =1 Then
Exit for
End If
next

End If

If nExitFlag =1 Then
Exit for
End If
Next

End Function

Posted in QTP, WEB | Tagged: , , , , , | 8 Comments »

 
%d bloggers like this: