title: Selenium Webdriver Java: Checking if a piece of script is present
body: <p>I have the following piece of HTML code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;bladibla&lt;/script&gt;
  &lt;script&gt;bladibla&lt;/script&gt;
  
  &lt;script&gt;
  
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  
    ga('create', 'UA-Bla', 'auto');
  
    ga('send', 'pageview');
  
  &lt;/script&gt;
  
  &lt;/head&gt; 
  
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I want to test if "go('send', 'pageview');" is present in that particular piece of code.</p>
  
  <p>I've tried the following, but that doesn't seem to be working:</p>
  
  <pre><code>String header = driver.findElement(By.xpath("//head[@'script'")).getText();
  Assert.assertTrue(header.contains("go('send', 'pageview');"));
  </code></pre>
  
  <p>Does anybody know how I can get Selenium Webdriver to check for the presence of "go('send', 'pageview');" in a Script Tag in the Head of a webpage? GetText doesn't seem to be working as it's a script...</p>