How to get element with css in PageObject

被刻印的时光 ゝ 提交于 2019-12-06 08:19:47

When you do element(:quote_text, :css => ".quote textarea"), it will only generate the methods (see doc):

quote_text #Returns the text of the element
quote_text_element #Returns the element
quote_text? #Returns if the element exists

Since you know it is a text area and want the text area methods, you should declare it as:

text_area(:quote_text, :css => ".quote textarea") 

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_text that seem to work:

#Using a block to locate the element:
text_area(:quote_text){ div_element(:class => "quote").text_area_element }

#Using xpath:
text_area(:quote_text, :xpath => '//div[@class="quote"]//textarea') 

I do not think you need self there (but I could be wrong).

Try this

quote_text = "text"

instead of

self.quote_text = "text"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!