WORKING WITH QTP

TestEveryThinG

VB Get All Web page text ( Including All Webelement )

Posted by rajivkumarnandvani on October 1, 2009

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

37 Responses to “VB Get All Web page text ( Including All Webelement )”

  1. uma said

    Good One..

  2. Thanks

  3. Manpreet said

    Hi the function is fine but ,the limitaion with this function is that if any data is present even in the textbox or there is multiple occurance of the same text. it falies. So i am still working on it to get a very accurate function which can resolve the issue .

    Comments to ur stite is that is a good one .

  4. Hi manpreetsingh,

    yes u are right.this function will check text anywhere on the page u want to check in a particular area for that u have to add that area div element.

    let me know if u able to do that/inform

  5. Indhu said

    Hi,

    I am trying to select a webcheck box by parametrizing the outer text of the corresponding webelement.

    Can anyone help me out???

  6. Hi indu,

    first you need to find text object(TD/LI/.etc) in web page based on your given text.After find the object you need to check that checkbox object which is near to your text is sibling to your object/or under means child.
    Best of luck.
    Incase you face any problem just send me(rajivkumarnandvani@gmail.com) your webpage with complete save as HTML so that i can figure out

    thanks

  7. bade raju said

    Hi,
    I used the code and not able to figure it out why sometimes it works and sometimes does not. In some pages it gets all the text and in another page it does not get the text. I am trying to evaluate what manpreet said above but could not figure out div element that you have mentioned. Do i need to update the code with more code? Please let me know.
    thanks,
    Raju

  8. Hi Raju,

    My means div is tag it can be any thing like frame or i frame / form anything that represent that area You can use IE developer Tool bar to figure out that area. Or you can send me html page with your query what problem you exactly facing and you can update the code as per your convenient.In case your page contain flash object that page text can not be figure out.

  9. RICHA said

    Rajivkumarnandvani ROCKS !!!!!!!!!!!

  10. Thanks Richa. 🙂

  11. Krunal said

    Hi,

    If I say, I want to Copy the Outertext/InnerHTML of that webelement and paste it on another screen/window then is it possible to do that? Is there any function or property which we can use to copy and paste the content/text inside the webelement?

    Thanks

  12. Hi krunal,

    for getting the webelement outertext value you can use following method GetROProperty(“outertext”)

    like
    myvariable = browser().page().yourwebelement().GetROProperty(“outertext”)

    then store this value into mercuryclipborad then this value getstored in ur windows clipborad.after that u can use
    refer mercury clipboard in qtp help file for proper details

    Set cb = CreateObject( “Mercury.Clipboard “)
    cb.Clear
    cb.SetText myvariable
    I m not getting ur point which u asking screen/window which window or screen is it remote another system/ ?

  13. Santosh said

    Great awesome code it helped me allot … it is like Ctrl+a code.. very very nice programing and good logic greatttttttttttttttttttttttttttttttttttttttttttttttttttttt

  14. Thanks Santosh 🙂

  15. Mike Trujillo said

    How would i use above code for a partial word search.
    My outertext returns 111.111.111Email but i search for 111.111.1111 and i get a return of False.

    Thanks

  16. hi mike,
    Its giving right return result because you searching 4 times 1 in last searching text while it outer text in last has 3 times 1.
    My outertext returns 111.111.111
    Email but i search for 111.111.1111
    and i get a return of False.
    🙂

  17. Mike Trujillo said

    Thanks Rajiv,
    My question is not that it isn’t working properly, but how do i edit it to return “True”
    outertext = 111.111.1111Email

    Public Function VerifyPhoneOnPageMorgan(byval objpage , byval Textvalue )
    On error resume next
    ‘——- 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].*”
    childobjdes(“outertext”).value =”.*[A-Za-z0-9].*”
    ‘ ———-Create ALL child object
    set allobj = objpage.ChildObjects(childobjdes)
    For i=1 to allobj.count-1
    output= output & allobj.Item(i).GetROProperty(“outertext”)
    Next
    If instr(1,lcase(output),lcase(“111.111.1111”)) > 0 Then
    VerifyPhoneOnPageMorgan= True
    Else
    VerifyPhoneOnPageMorgan= False
    End If
    On Error GoTo 0
    End Function

  18. Hi Mike your code will work. it’s look fine

  19. Mike Trujillo said

    Thanks for your time Rajiv, unfortunetly i only get a value of true if i actually use instr(1,lcase(output),lcase(“111.111.1111Email″)) > 0 Then.

    Should i be using a match or contains somewhere?
    Thank you again your help is much appriated.

  20. Hi just check your out put value in print statement like.

    print output
    and then find is the value is coming or not .. might be at run time when you capturing the output value is not contains the expected text..

  21. santosh gaddam said

    Hi ….

    i want to find out one text in a webpage but that is in this format

    ASP Error: Undefined variable CurrentDNSServers_1_DNSIPAddress At line 1

    i am not able to get this text with above code..

    can u please help me out from this problem

    Thanks,
    Santosh

  22. santosh gaddam said

    Hi ….

    i want to find out one text in a webpage but that is in this format

    ASP Error: Undefined variable CurrentDNSServers_1_DNSIPAddress At line 1

    i want to find out this text “ASP Error:”

    i am not able to get this text with above code..

    can u please help me out from this problem

    Thanks,
    Santosh

  23. Hi santosh,

    Thanks for reading. make sure you are executing the above code after the error comes.

    thanks

  24. Anonymous said

    Nice Post Rajiv 🙂

  25. Can anybody help me in my query…

    I want to highlight the text, in case user finds the text on screen.

  26. Hi tarun,

    Please find the below link for your query.
    http://testeverythingqtp.blogspot.com/2011/04/highlight-text-on-page-using-qtp.html

  27. Dani said

    Hi Rajiv,

    Any idea how to check if a web paje is loaded fully when it has an ajax call?

  28. Hi dani.

    In that case u have to check that particular text/element on that place where ajax is calling and wait until that element/text comes.

    Thanks

  29. Sameer Verma said

    Hi,
    can any one please help me in implementing this logic.

    My system details: IE 9, QTP 11, window 7 (I hope that’s sufficient)

    the few area which are not turning positive results are ”

    1) set objpage = Browser(“abcd”).Page(“abcd”) : When I check in debug log : objpage is coming
    2) this particular code seems to be not working for me too,

    For i=1 to allobj.count-1
    output = output &allobj.Item(i).GetROProperty(“outertext”)
    Next

    I’ll really appreciate your help.

    Thanks

    Sameer

  30. Hi,
    you have missed the child object creation. please create the child object then you find the objects under page object else it will not count the object under the page.

    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)

  31. Caroline said

    hi,
    I’m very new to QTP . I’m searching some code sample and landing to this page.
    can you help me with ?
    on the website every time user select address from drop down list and the click update button
    I have to check the text/element make sure it update the same as user selected from drop down list.
    how do I code for it ? I can send you the screen shot if needed.

  32. First get the selected text from drop down list in a variable.
    then search the text in the area where you want the updated value. If you find the text on that area means its updated else not.

  33. Carolline said

    thanks for your quick responsed

    here is my code but for some reason when I run debug from step
    it’s stop after update button click so, I never get thru FUNCTION VerifyTextPresentOnPage
    your help is really appreciated.

    Set oPage = Browser( “micClass:=Browser”).Page(“micClass:=Page”)

    ConfigureServiceBilling = “ConfigureServiceBilling_RS_73877__billingAddress”
    ConfigureServiceBillingLovName = ConstantsMgr.LOV_NAME & ConfigureServiceBilling
    ServiceBilling = RandomNumber(1,6)
    oPage.weblist(ConfigureServiceBillingLovName).Select ServiceBilling

    UtilMgr.clickStandardButton(ConstantsMgr.BT_UPDATE)

    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-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

  34. Shakeel Iqbal said

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

  35. TesterVinni said

    My task in hand required to automate a page which ask random questions, based on customer’s credit history. I am unable to fetch the question from the inner html/innertext/outertext of the Webelement of the webpage. Rajiv pointed out to check for null values OR “”.
    Below is the working code:-

    set objpage1 = Browser(“name:=Cards.*”).Page(“title:=Cards.*”)

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

    oTextValue1 = “With which branch location do you have an active personal or home equity line of credit?”

    msgbox VerifyTextPresentInPage(objpage1,oChildobjdes1,oTextValue1)

    ‘— Function Starts here —
    Function VerifyTextPresentInPage(oBjpage,oChildobjdes,oTextvalue)
    On error resume next

    set allobj = oBjpage.ChildObjects(oChildobjdes)

    For i=1 to allobj.count-1
    output = allobj.Item(i).GetROProperty(“outertext”)

    If (output “”) And (NOT IsNull(output)) Then
    If InStr(1,output,oTextvalue) > 0 Then
    VerifyTextPresentInPage = True
    Exit Function
    Else
    VerifyTextPresentInPage = False
    End If
    End If
    Next

    On Error GoTo 0
    End Function

    – Regards,
    TesterVinni

  36. Vinni said

    I’ve facing another problem now, where I am unable to extract the innertext/outertext from a WebElement. Though I am able to identify & highlight the WebElement using Object Spy, but when I try extracting its value programmatically, its returning empty string & highlight is also not working.
    ‘ — My code
    Browser(“name:=Cards.*”).Page(“title:=Cards.*”).highlight ‘ —> This works
    Browser(“name:=Cards.*”).Page(“title:=Cards.*”).WebElement(“class:=dsk-block”,”html id:=postStatus”).Highlight ‘ —> UFT throws General run error
    Msgbox Browser(“name:=Cards.*”).Page(“title:=Cards.*”).WebElement(“class:=dsk-block”,”html id:=postStatus”).GetROProperty(“outertext”) ‘—> Returns blank
    Msgbox Browser(“name:=Cards.*”).Page(“title:=Cards.*”).WebElement(“class:=dsk-block”,”html id:=postStatus”).GetROProperty(“innertext”) ‘—> Returns blank

    -Thanks in advance,
    Vinni!

  37. Sindhu said

    Hi Rajivkumarnandvani ,

    Need your help on this,

    I have a scenario to compare all the fields on webpage and Datatable.

    Can you please let me know how to proceed?

Leave a comment