您好我想撰写邮件,邮件的textarea有以下HTML代码
任何人都可以帮我解决如何使用watir访问它的过程已完成以下步骤但无法获取
irb
require 'rubygems'
require 'watir'
@ie.body(:id,':158').set 'text'
我的系统配置
IE-8
Windows-7
<div class="Ar Au" id=":88" style="display: block;">
<iframe tabIndex="1" class="Am Al editable" id=":83" src="html/compose/static_files/blank_quirks.html" frameBorder="0" style="padding-bottom: 0px; background-color: white; padding-left: 0px; padding-right: 0px; height: 245px; overflow: visible; padding-top: 0px;" allowTransparency="allowtransparency" closure_lm_423419="null">
<body class="editable LW-avf" id=":158" role="textbox" contentEditable="true"
hideFocus="hidefocus" closure_lm_478727="[object Object]" g_editable="true"/>
答案 0 :(得分:0)
对于非输入的可编辑元素,即本例中的body元素,没有set
方法。对于这些类型的元素,您需要使用send_keys
方法。假设当前版本的Watir,以下内容将起作用:
@ie.iframe(:id => ':83').body(:id, ':158').send_keys('text')
因为iframe中只应该有一个body元素,所以你也可以这样做:
@ie.iframe(:id => ':83').body.send_keys('text')
但是,鉴于您使用的是Watir v1.6.7,其中有几种方法不同或不存在。例如,没有iframe
或body
方法。同样,元素没有send_keys
方法。相反,您需要将焦点放在body元素上,然后send_keys
到浏览器。
@ie.frame(:id, ':83').element(:id, ':158').focus
@ie.send_keys('text')
请注意,该元素需要处于焦点,因此在执行此操作时请勿将焦点从浏览器中移开。