In the project on which I add tests, I have some elements complicated to “get”.
The html of my textarea :
<div class="quote">
<div class="clearfix">
<div class="icon"></div>
<div class="text">
<span class="yui3-widget yui3-inputwidget yui3-textareawidget yui3-textareawidget-focused" style="">
<span class="yui3-textareawidget-content">
<textarea name="" placeholder=""></textarea>
</span>
</span>
</div>
<div class="author">
(...) other text_field
</div>
</div>
</div>
</div>
For the moment, I use this line to set value
@browser.element(:css => ".quote textarea").send_keys "test"
In PageObject, I should declare the element and use it :
# declaration at the top
element(:quote_text, :css => ".quote textarea")
# use it where I need
self.quote_text = "text"
But I get this error when I use :
undefined method `quote_text=' for #<PublishPage:0x33843c0> (NoMethodError)
Where am I wrong ?
When you do
element(:quote_text, :css => ".quote textarea"), it will only generate the methods (see doc):Since you know it is a text area and want the text area methods, you should declare it as:
This will give you the
quote_text=method you expect (see doc).Update – Since Watir-Webdriver only support css-selectors at the element class (see Issue 124), you will also need to change the locator. Two alternative declarations for
quote_textthat seem to work: