SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 10 of 10
  1. #1
    Member
    Join Date
    Jan 2008
    Posts
    284
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    How to search for a String in webpage source code?

    On a webpage ->under View source ---> i need to search for a specific string ( String location changes every time and it will be under diff tags)

    If I find the string in the source code test passes other wise a fail.

    Can I get some pointers to approach this scenario?

  2. #2
    Moderator
    Join Date
    Oct 2010
    Location
    Norway
    Posts
    3,265
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: How to search for a String webpage source code?

    jyoo,

    Try this.

    To get the html:
    strCode = Browser().Page().Object.innerHtml

    To get the innerText:
    strCode = Browser().Page().Object.innerText


    If Instr(strCode, YOUR_TEXT) <> 0 Then
    Msgbox "Pass"
    Else
    Msgbox "Fail"
    End If
    Rajkumar

  3. #3
    Member
    Join Date
    Jan 2008
    Posts
    284
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to search for a String webpage source code?

    Thanks, the above code worked.

    But I ran into another issue.

    I was trying to pull all the <img src>elements but one the <img src> is commented like below.


    <!--<img src="https://www.abc.com/xxxx/process.php?PROGID=1548&TYPE=saleb&CLASS=t ier_d&TRANSID=7346437" height="2" width="1">-->

    Here is the code i am using to pull the uncommented <img src> elements which is working great.But not working for the one in comments.

    Set img = Browser("Google").Page("Submit").Object.all.tags(" img")

    msgbox img.length

    For i=0 to img.length-1
    msgbox img(i).src
    Next

    Is there a way i get this also?

  4. #4
    Moderator
    Join Date
    Oct 2010
    Location
    Norway
    Posts
    3,265
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: How to search for a String webpage source code?

    [ QUOTE ]

    <!--<img src="https://www.abc.com/xxxx/process.php?PROGID=1548&TYPE=saleb&CLASS=t ier_d&TRANSID=7346437" height="2" width="1">-->


    [/ QUOTE ]

    This is just a comment tag and it will be ignored by the browser. Why do you need the comment?
    Rajkumar

  5. #5
    Member
    Join Date
    Jan 2008
    Posts
    284
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to search for a String webpage source code?

    It is SEO logic,That is the pixel code (which fires when navigated to the page and it is commented in the test environments and not in prod)i need to verify that exists on the source of the webpage.That is the reason i need to capture that commented element.



    Is there a way to do this?

  6. #6
    Senior Member
    Join Date
    Jul 2004
    Location
    Marietta, Georgia
    Posts
    317
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to search for a String webpage source code?

    Try a regular expression. Something like:

    theHTML = Browser("name:=.*").Page("name:=.*").Object.docume ntElement.innerhtml
    Set re = New RegExp
    re.Pattern = "(<img.*?&gt"
    re.IgnoreCase = True
    re.Global = True
    Set oMatches = re.Execute(theHTML)
    For Each reMatch in oMatches
    MsgBox reMatch
    Next
    <font color="#6B6B6B">Scott Genevish
    Principal Consultant
    Designed Quality</font>

  7. #7
    Member
    Join Date
    Jan 2008
    Posts
    284
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to search for a String webpage source code?

    Thank you genevish,Now I get the img elements which are commented.

    I am comparing actual Vs expected for some reason it always Fails.Do you see any reason why this fails?
    --Code below

    sExpect ="&lt;img src="&amp;"https://www.abc.com/xxxx/process.php?PROGID=1548&amp;TYPE=saleb&amp;CLASS=t ier_d&amp;TRANSID=7346437"&amp;"height="&amp;"2"&a mp;"width="&amp;"1"&amp;"&gt;"

    theHTML = Browser("name:=.*").Page("name:=.*").Object.docume ntElement.innerhtml
    Set re = New RegExp
    re.Pattern = "(&lt;img.*?&gt"
    re.IgnoreCase = True
    re.Global = True
    Set oMatches = re.Execute(theHTML)
    For Each reMatch in oMatches
    'MsgBox reMatch
    If Instr(reMatch,sExpect) &lt;&gt;0Then
    msgbox "PASS"
    else
    msgbox "FAIL"
    End If
    Next

    Thanks

  8. #8
    Member
    Join Date
    Jan 2008
    Posts
    284
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to search for a String webpage source code?

    i understood the issue

    actual string is

    &lt;img src="https://www.abc.com/xxxx/process.php?PROGID=1548&amp;TYPE=saleb&amp;CLASS=t ier_d&amp;TRANSID=7346437" height="2" width="1"&gt;

    in the expected version

    sExpect ="&lt;img src="&amp;"https://www.abc.com/xxxx/process.php?PROGID=1548&amp;TYPE=saleb&amp;CLASS=t ier_d&amp;TRANSID=7346437"&amp;"height="&amp;"2"&a mp;"width="&amp;"1"&amp;"&gt;"

    which displays like this

    &lt;img src=https://www.abc.com/xxxx/process.php?PROGID=1548&amp;TYPE=saleb&amp;CLASS=t ier_d&amp;TRANSID=7346437" height="2" width="1"&gt;


    but i need to have this quotes also infront of https &lt;img src = "https..................&gt;

    I tried different ways it throws warning.
    How to I append double quotes in qtp?

  9. #9
    Member
    Join Date
    Jan 2008
    Posts
    284
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to search for a String webpage source code?

    I got it with chr(34).

  10. #10
    Senior Member
    Join Date
    Jul 2004
    Location
    Marietta, Georgia
    Posts
    317
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to search for a String webpage source code?

    Sorry, been on vacation for a week. You can also escape the quotes (with another quote):

    sExpect ="&lt;img src=""https://www.abc.com/xxxx/process.php?PROGID=1548&amp;TYPE=saleb&amp;CLASS=t ier_d&amp;TRANSID=7346437"" height=""2"" width=""1""&gt;"
    <font color="#6B6B6B">Scott Genevish
    Principal Consultant
    Designed Quality</font>

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 08:23 PM.

Copyright BetaSoft Inc.