How to Use GetElementsBytagName Method in QTP explained with Code
In this post, we will discuss how to use GetElementsbyTagName to input values in a edit box, count number of editbox, links , and count number of rows in a particular table. Please suggest in case user miss anything in the code. We can similarly use GetElementsbyTagName in a variety of purposes and manipulate the html
Code to find number of links in a page.
set objLink = Browser("title:=.*","index:=0").Page(title:=.*).Object.GetElementsByTagName("a")
intLinks = objLink.length
Code to Identify number of edit box in the page.
set objLink = Browser("title:=.*","index:=0").Page(title:=.*).Object.GetElementsByTagName("input")
intLinks = objLink.length
Code to input Data in a field using HTML DOM
set objEdit = Browser("title:=.*","index:=0").Page(title:=.*).Object.GetElementsByTagName("input")
for each editbox in objEdit
If editbox.classname = <strClassName>
editbox.innertext = <strSetVsalue>
Exit For
End If
Next
Code to count number of rows in a table
set objTable = Browser("title:=.*","index:=0").Page(title:=.*).Object.GetElementsByTagName("table")
for each Tbl in objEdit
If Tbl.classname = <strTableClassName>
set objrow = tbl.getelementsbyTagName("tr")
Msgbox objrow.length
End If
Next
No comments:
Post a Comment