# WWW::Mechanize problem

**URL:** <https://www.ruby-forum.com/t/www-mechanize-problem/82568>\
**Category:** Ruby\
**Created:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/www-mechanize-problem/82568 "2007-01-19T16:31:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/www-mechanize-problem/82568/1 "2007-01-19T16:31:24Z")

</div>

Hello,

I could not yet figure out how to work around this problem:

agent = WWW::Mechanize.new  
page = agent.get(“[http://www.amazon.com/](http://www.amazon.com/)”)  
search\_form = page.forms.with.name(“site-search”).first  
search\_form.field-keywords = “Ruby”

i.e. that the name of the input field is ‘field-keywords’, so Ruby  
thinks (rightfully of course) that I am calling the method ‘field’ of  
the object search\_form and of course then the whole thing does not work.  
Any suggestions?

TIA,  
Peter

\_\_  
[http://www.rubyrailways.com](http://www.rubyrailways.com)

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [September 25, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/www-mechanize-problem/82568/2 "2007-09-25T22:36:52Z")

</div>

Peter S. wrote:

> thinks (rightfully of course) that I am calling the method ‘field’ of  
> the object search\_form and of course then the whole thing does not work.  
> Any suggestions?

You could try

search\_form[“field-keyword”] = “Ruby”

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [September 25, 2007, 10:38pm UTC](https://www.ruby-forum.com/t/www-mechanize-problem/82568/3 "2007-09-25T22:38:05Z")

</div>

On 1/13/07, Peter S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> thinks (rightfully of course) that I am calling the method ‘field’ of  
> the object search\_form and of course then the whole thing does not work.  
> Any suggestions?

guessing from  
[http://mechanize.rubyforge.org/classes/WWW/Mechanize/Form.html:](http://mechanize.rubyforge.org/classes/WWW/Mechanize/Form.html:)

search\_form[‘field-keywords’] = “Ruby”

or you could do

search\_form.send(:‘field-keywords=’, “Ruby”)

---

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [September 25, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/www-mechanize-problem/82568/4 "2007-09-25T22:49:07Z")

</div>

Stefan M. wrote:

> > i.e. that the name of the input field is ‘field-keywords’, so Ruby  
> > thinks (rightfully of course) that I am calling the method ‘field’ of  
> > the object search\_form and of course then the whole thing does not work.  
> > Any suggestions?
> 
> You could try
> 
> search\_form[“field-keyword”] = “Ruby”  
> Hey, that worked! Thanks a lot.

SG,  
Peter

\_\_  
[http://www.rubyrailways.com](http://www.rubyrailways.com)
