相关疑难解决方法(0)

如何使用webdriver获取textarea的文本内容?

我正在尝试使用Python中的webdriver在 HTML表单中获取textarea的内容.

我收到了文字,但缺少换行符.该硒文档是几乎无用的; 他们说:

class selenium.webdriver.remote.webelement.WebElement(parent,id_)

[...]

text:获取元素的文本.

我目前正在做以下事情:

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))
Run Code Online (Sandbox Code Playgroud)

这将打印textarea内容的Python unicode字符串的表示形式,除了所有换行符已被空格替换.卫生署!

不确定我是否面临文本编码问题,selenium/webdriver错误(无法在跟踪器中找到它)或用户错误.

有没有不同的方法来做到这一点?

编辑:我只是尝试了Chrome ...工作正常.我向selenium的问题跟踪器报告了一个错误.Sam的解决方法(下面接受的答案)适用于Firefox,但有一点需要注意:符号在返回的字符串中转换为HTML实体代码.这没什么大不了的.

python selenium webdriver

7
推荐指数
2
解决办法
8626
查看次数

标签 统计

python ×1

selenium ×1

webdriver ×1