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.
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:
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:
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. Watirwebdriver.com
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?
Sorry, I misread the question. I'm too used to people posting questions
about webdriver
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.