2016-09-28 20 views
2

我試圖用機械化填寫表格。它可以工作,但一些輸入名稱有[],並且失敗。機械化 - 用輸入名稱中的方括號填寫表格

<input id="titleen_US" type="text" name="title[en_US]" value=""> 

我試圖

a = Mechanize.new 
page = a.get("http://myurl.com") 
first_form = page.form('item') 
first_form.title[en_US] = 'This is my title' 

但我有undefined method 'title='。 有什麼想法? thx

回答

2

請繼續嘗試。

a = Mechanize.new 
page = a.get("http://myurl.com") 
first_form = page.form('item') 

title_field = first_form.field_with(:name => "title[en_US]") 
title_field.value = "whatever_title" 

OR

a = Mechanize.new 
page = a.get("http://myurl.com") 
first_form = page.form('item') 

first_form['title[en_US]'] = "title" 
+0

THX再次,它的工作原理 – Rubyx

+0

@Rubyx歡迎.. –