Reputation: 391
I was unable to set text into the text area with browser.text_field(:id,"area").set "1=1"
. When i typed manually i noticed that the text("1=1") i typed is stored across spans as given below.
<pre>
<span class="number">1</span> # the text 1 is stored here and followed by "=1" in next spans
<span class="operator">=</span>
<span class="number">1</span>
</pre>
Is there any other way that i can set text into the text area?
Upvotes: 2
Views: 1969
Reputation: 545
It is important to send keys on proper element. In my case, after some experimentations, that was:
<div class="redactor_text redactor_optional redactor_redactor redactor_editor" contenteditable="true" dir="ltr" style="min-height: 120px;"></div>
Editor was defined with this html:
<div class="redactor_box"><ul class="redactor_toolbar" id="redactor_toolbar_0"><li><a href="javascript:;" title="Bold" tabindex="-1" class="re-icon re-bold"></a></li><li><a href="javascript:;" title="Italic" tabindex="-1" class="re-icon re-italic"></a></li><li><a href="javascript:;" title="Underline" tabindex="-1" class="re-icon re-underline"></a></li><li><a href="javascript:;" title="Link" tabindex="-1" class="re-icon re-link"></a></li><li><a href="javascript:;" title="Superscript" tabindex="-1" class="re-icon re-superscript fa-redactor-btn"><i class="fa icon-superscript"></i></a></li><li><a href="javascript:;" title="Subscript" tabindex="-1" class="re-icon re-subscript fa-redactor-btn"><i class="fa icon-subscript"></i></a></li></ul><div class="redactor_text redactor_optional redactor_redactor redactor_editor" contenteditable="true" dir="ltr" style="min-height: 120px;"></div><textarea class="text optional redactor" data-limit="450" data-persist="garlic" data-min-height="120" name="lesson[intro]" id="lesson_intro" dir="ltr" style="display: none;"></textarea></div>
Upvotes: 0
Reputation: 57262
This worked for me:
require "watir-webdriver"
browser = Watir::Browser.new
browser.goto "ideone.com"
browser.div(:id => "file_div").textarea.set "1=1"
Are you sure you need to set text in textarea? If you are dealing with wysiwyg editor, you probably need to use send_keys
:
browser.pre.send_keys "1=1"
More information: http://watirwebdriver.com/wysiwyg-editors/
Upvotes: 1