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:
[JavaScript]script type=“text/javascript”
try {
var pageTracker = _gat._getTracker(“UA-222222-3″);
pageTracker._trackPageview();
} catch(err) {}script
[/JavaScript]
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


Author: Pavandeep Puddupakkam on February 19, 2010
Category: Automation Tips, Selenium RC, Software Testing, XPath
Tags: , ,
Google Webdriver Forum -The Online Community for Google Webdriver and Selenium RC Users and Professionals

Leave a Reply

Last articles