How to use selenium to check for google analytics on a web page

I have used xpath to verify if a particular string is available on the web page. Using the same concept I am now able to verify if google analytics code is available on the web page.

 

Here is the example:

Say my google analytics code is something like this:

<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-222222-3");
pageTracker._trackPageview();
} catch(err) {}</script>
 
The xpath for that is  //script[@type="text/javascript"][contains(text(), 'UA-222222-3')]
 
Then you use verifyElementPresent in selenium. I hope this will be useful for you all.
 
<tr>
<td>verifyElementPresent</td>
<td>//script[@type='text/javascript'][contains(text(), 'UA-222222-3')]</td>
<td></td>
</tr> 
Submitted by Puddupakkam Pavandeep 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: wiki
Posted on: 2/19/2010 at 12:05 PM
Tags: , , , ,
Categories: Software Testing
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Comments

Add comment


 

  Country flag

biuquote
  • Comment
  • Preview
Loading