TESTEVERYTHING

Wednesday, 27 July 2011

VB Get All Web page text ( Including All Webelement )

Hi All,
Some Time we have to check that particular text is present on page or not during automation. If we get the page outer HTML in QTP we can not  get the whole text of all element like frame , webtable . div.etc…
So i created a function which will  check that the given text is present on page or not If Text present on page it will return True else False
REM  ——-   Set page object     ———-
set objpage = Browser(“BrowserName”).Page(“Pagename”)
msgbox   VerifyTextPresentOnPage(objpage ,”rajiv” )
Function VerifyTextPresentOnPage(byval objpage , byval Textvalue )
On error resume next

REM ——- Create child object description
Set childobjdes = Description.Create()
childobjdes(“micclass”).value=”WebElement”
childobjdes(“html tag”).value=”.*[A-Za-z0-9].*”
childobjdes(“outertext”).value =”.*[A-Za-z0-9].*”

REM  ———-Create ALL child object
set allobj = objpage.ChildObjects(childobjdes)
REM  get all  web element  outer text from web page and store in output variable
For i=1 to allobj.count-1
output=  output   & allobj.Item(i).GetROProperty(“outertext”)
Next
REM  now compare the value if the given value find or not
If instr(1,lcase(output),lcase(Textvalue)) > 0  Then

rem return true if found
VerifyTextPresentOnPage= True
Else

rem return true if  not found
VerifyTextPresentOnPage= False
End If
On Error GoTo
0
End Function

7 comments:

Pruthvi Reddy said...

Excellent Rajiv it worked like a gem..

Thank You.
Pruthvi

RajivKumarNandvani said...

Thanks for reading the blog :)

Anonymous said...

This is Pavan. Thanks for sharing.

Shakeel AI said...

strPagetext = Browser("Br").Page("Pg").WebElement("xpath:=/html/body").GetROProperty("innertext")

Sandy treks said...
This comment has been removed by the author.
Sandy treks said...

Good Explanation, Just want to correct one thing
Loop should start from 0
eg.
For i=0 to allobj.count-1
output= output & allobj.Item(i).GetROProperty(“outertext”)
Next

Please correct me Rajiv, If I am wrong.

Dinesh N said...

am getting expected expression errors :(

Post a Comment

Which one is right ?

Translate







Tweet