No form name in page - Ruby Mechanize

Hi All,

I am parsing a page using Ruby mechanize. Now on one the pages i have
select some checkboxes. I analysed the forms in my page object using:
puts page.forms - and i get the id’s of the forms I think eg, 0x238…
and the form name is nil.
So how would i go about checking/un-checking a checkobx in the form if i
cannot search a form and then parse its contents?
I think ideally i would use something like this:
searchForm=page.form(‘form_name’) - and then in that specific form in
look for checkbox and then click it.

Help much appreciated.

You might be able to narrow it down via a specific parent or child
element, and work from there.

When all else fails, use index.

Joel P. wrote in post #1101638:

You might be able to narrow it down via a specific parent or child
element, and work from there.

When all else fails, use index.

Thanks a lot Joel.

I was able to search for the form using below:
checkboxForm = page.form_with(:action => ‘colchange.cgi’)

Now when I pp checkboxForm i get a list of all the checkboxes in the
form.
But the "value: " is shown as null for all checkboxes which are checked
even.
Shouldnt this be check or uncheck? Then i click a specific checkbox and
fetch a new page object, but not getting the desired results. If you
could please help. Below is the snippet of script:

checkboxForm = page.form_with(:action => ‘colchange.cgi’)

#Setting the state of checkbox
checkboxForm.checkbox_with(:name => ‘column_opendate’).check

page=pageAgent.submit(checkboxForm,checkboxForm.buttons.first)

#Clicking the CSV link
page = pageAgent.page.link_with(:text => ‘CSV’).click

#Retrieving the uri from the object and storing as string in the var
uriDownload=page.uri.to_s

#Downloading and saving the CSV file
agent.pluggable_parser.default = Mechanize::Download
agent.get(uriDownload).save(‘openBugs.csv’)


Based on the above code the CSV file should be showing additional column
“opendate” for which i have checked the ‘column_opendate’ checkbox.

regards,

Rochit

in watir-webdriver (which uses selenium-webdriver under the surface) it
is as simple as “.set?” and “.set”. You can even pass a boolean
“.set(true) / .set(false)”. Use it, it will make your code much simpler
to write and read. The documentation is much easier to read as well.
http://watirwebdriver.com/web-elements/

In selenium-webdriver raw, I think you have to use “.click” to set a
checkbox, and “.IsSelected”.

Try this link for a collection of tips on selenium-webdriver’s
checkboxes:

Sorry, I misread the question. I’m too used to people posting questions
about webdriver :slight_smile:

I haven’t used mechanize myself, but have you tried “.selected = true”?

Joel P. wrote in post #1101908:

in watir-webdriver (which uses selenium-webdriver under the surface) it
is as simple as “.set?” and “.set”. You can even pass a boolean
“.set(true) / .set(false)”. Use it, it will make your code much simpler
to write and read. The documentation is much easier to read as well.
Loading...

In selenium-webdriver raw, I think you have to use “.click” to set a
checkbox, and “.IsSelected”.

Try this link for a collection of tips on selenium-webdriver’s
checkboxes:

Thanks Joel. I will try this. But was wondering is there anything wrong
i m doing with Mechanize?

Joel P. wrote in post #1101912:

Sorry, I misread the question. I’m too used to people posting questions
about webdriver :slight_smile:

I haven’t used mechanize myself, but have you tried “.selected = true”?

Hi Joel. I was able to resolve the issue. Actually i was checking the
checkbox correctly but afterwards was not downloading the csv file with
correct url.

Issue is resolved :). Thanks for your support.