Rubyx Rubyx - 2 months ago 7
Ruby Question

Mechanize - Fill form with square brackets in input name

i'm trying to fill a form with Mechanize. It works but some of the input name have [] inside and it fails.

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


I tried

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


But i have
undefined method 'title='
.
Any idea? thx

Answer

Try Following.

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"