title: Get content of HTML comment tag with Selenium
body: <p>I find it difficult to get the content of an HTML comment tag <code>&lt;!-- stuff --&gt;</code> included in the <code>head</code> tag of an HTML page using <strong>python 2.7</strong> and <strong>selenium</strong>.</p>
  
  <pre><code>&lt;head&gt;
     &lt;!-- I would like to get this sentence --&gt;
     [...]
  &lt;/head&gt;
  </code></pre>
  
  <p>I got the XPath of that comment using FirePath/FireBug (so I am assuming it is correct): <code>html/head/comment()[1]</code>. </p>
  
  <p>Then:</p>
  
  <ul>
  <li>this <code>given_driver.find_element_by_xpath('html/head/comment()[1]')</code> gives me <code>InvalidSelectorException</code> saying <code>Message: The given selector html/head/comment()[1] is either invalid or does not result in a WebElement. The following error occurred:
  InvalidSelectorError: The result of the xpath expression "html/head/comment()[1]" is: [object Comment]. It should be an element.</code></li>
  <li>this <code>head_element = given_driver.find_element_by_xpath('html/head')</code> then gives me the whole HTML code in the <code>head</code> tag with <code>head_element.get_attribute('innerHTML')</code> like: <code>u'&lt;!-- I would like to get this sentence --&gt;\n         [...]</code></li>
  </ul>
  
  <p>But I would like to get just the content of the comment tag inside the <code>head</code> tag. I am wondering this is not possible with Selenium, but it seems strange to me. How could I get it?</p>