基于本人不会JavaScript,不能像大神一样写出很牛X的方法,只能使用者屌丝方法了,不过很容易理解。
我使用的是ueditor富文本框
<span style="font-size:18px;"><iframe id="ueditor_0" width="100%" height="100%" ">
<html class="view_0" >
<head>
<body class="view_1" contenteditable="true" spellcheck="false">
<p>
<br>
</p>
</body>
</html>
</iframe></span>
1、我的富文本框是在一个iframe中,进入iframe的方法在上一篇文章中已经介绍过,:switch_to_frame("ueditor_0")
2、然后定位到输入框,也就是<body>···</body>:find_element_by_class_name("view_1")
3、这一步是最重要的一步(但是有时候不输入也行),就是进行一个TAB键的操作:send_keys(Keys.TAB)
4、现在就可以往里面写内容了:send_keys("哈哈")
下面是完整的脚本:
driver.switch_to_frame("ueditor_0") #通过frame的id定位ueditor富文本框
yy=driver.find_element_by_class_name("view_1") #定位frame中的输入框
yy.send_keys(Keys.TAB)
<pre name="code" class="python">yy.clear()
yy.send_keys(u"1234567890\n!@#$%^&*()<>?.,\n大漠孤烟直,长河落日圆。\n abc def ghi")