title: How do I get the text contents of a textarea with webdriver?
body: <p>I'm trying to get the contents of a <a href="http://www.w3.org/TR/html4/interact/forms.html#h-17.7" rel="nofollow noreferrer">textarea</a> in an HTML form using <a href="http://code.google.com/p/selenium/wiki/PythonBindings" rel="nofollow noreferrer">webdriver in Python</a>.</p>
  
  <p>I'm getting the text, but newlines are missing. The <a href="http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_remote/selenium.webdriver.remote.webelement.html#selenium.webdriver.remote.webelement.WebElement.text" rel="nofollow noreferrer">selenium docs</a> are pretty much useless; they say:</p>
  
  <blockquote>
    <p>class selenium.webdriver.remote.webelement.WebElement(parent, id_)</p>
    
    <p>[...]</p>
    
    <p>text: Gets the text of the element.</p>
  </blockquote>
  
  <p>I'm currently doing the following:</p>
  
  <pre><code>from selenium import webdriver
  
  # open the browser and web site
  b = webdriver.Firefox()
  b.get('http://www.example.com')
  
  # get the textarea element
  textbox = b.find_element_by_name('textbox')
  
  # print the contents of the textarea
  print(repr(textbox.text))
  </code></pre>
  
  <p>This prints the representation of a Python unicode string of the textarea's contents, except all the newlines have been replaced by spaces. Doh!</p>
  
  <p>Not sure if I'm facing a text encoding issue, selenium/webdriver bug (couldn't find it in the tracker), or user error.</p>
  
  <p>Is there a different way to do this?</p>
  
  <p><strong>EDIT</strong>: I just gave Chrome a try... works fine. I reported a <a href="http://code.google.com/p/selenium/issues/detail?id=2956" rel="nofollow noreferrer">bug</a> to selenium's issue tracker. Sam's workaround (the accepted answer below) works in Firefox with one caveat: symbols are converted to HTML entity codes in the returned string. This is <a href="https://stackoverflow.com/a/2474992/182642">no big deal</a>.</p>