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
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-1output= 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= TrueElse
rem return true if not found
VerifyTextPresentOnPage= FalseEnd If
On Error GoTo 0
End Function
7 comments:
Excellent Rajiv it worked like a gem..
Thank You.
Pruthvi
Thanks for reading the blog :)
This is Pavan. Thanks for sharing.
strPagetext = Browser("Br").Page("Pg").WebElement("xpath:=/html/body").GetROProperty("innertext")
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.
am getting expected expression errors :(
Post a Comment