2011-01-30 58 views
0

試圖填補在文本輸入使用webrat黃瓜錯誤?如果標籤包含超過輸入

When I fill in "Last name" with "Doe" 
給這個HTML

<label> 
    <span>Last name</span> 
    <input class="title" id="user_last_name" name="user[last_name]" size="30" type="text" /> 
    <small>Some hint text here</small> 
</label> 

將拋出一個

Webrat沒有發現場輸入元素的Webrat::NotFoundError錯誤。

如果我刪除了<small>標籤,該字段就可以找到。

這是一個錯誤?是否存在解決方法?

回答

1

這不是很漂亮的HTML。它應該是這樣的:

<p> 
    <label for='user_last_name'>Last Name</label> 
    <input id='user_last_name' [ other stuff]> 
    <small>Some hint text here</small> 
</p> 

或者在條款的ActionView:

<p> 
    <%= f.label :last_name %> 
    <%= f.text_field :last_name %> 
    <small>Some hint text here</small> 
</p> 
+0

謝謝您的回答。是的,如果它很漂亮,我想這是值得商榷的。這是有效的,儘管(至少在我的腦海裏確實很有道理;)),因此不應該拋棄Webrat,或者我看到這個錯誤? – polarblau 2011-01-30 22:24:54