title: How can I use jQuery with selenium execute_script method?
body: <p>How can I use jQuery with the selenium <code>execute_script</code> method, if the current page isn't already using jQuery?</p>
  
  <p>For example:</p>
  
  <pre><code>from selenium import webdriver
  driver = webdriver.Firefox()
  driver.get(url)
  driver.execute_script('$("#id").wrap("&lt;h1&gt;&lt;/h1&gt;")')
  </code></pre>
  
  <p>I've tried adding a script like this:</p>
  
  <pre><code>driver.execute_script(
  "var jquery_script = document.createElement('script'); 
  jquery_script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
  document.findElementsByTag('head')[0].appendChild(jquery_script)"
  )
  </code></pre>
  
  <p>But I get errors saying that the jquery_script variable is undefined.</p>