KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to get the contents of a textarea in an HTML form using webdriver in Python . I'm getting the text, but newlines are missing. The selenium docs are pretty much useless; they say: class selenium.webdriver.remote.webelement.WebElement(parent, id_) [...] text: Gets the text of the element. I'm currently doing the following: 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)) This prints the representation of a Python unicode string of the textarea's contents, except all the newlines have been replaced by spaces. Doh! Not sure if I'm facing a text encoding issue, selenium/webdriver bug (couldn't find it in the tracker), or user error. Is there a different way to do this? EDIT : I just gave Chrome a try... works fine. I reported a bug 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 no big deal .
Tags (comma-separated)
Save Edits
Cancel