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.
on 2013-03-14 18:22
on 2013-03-14 18:27
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.
on 2013-03-16 05:07
Joel Pearson 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
on 2013-03-16 11:03
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: http://selenium-tutorial.blogspot.co.uk/2012/10/se...
on 2013-03-16 11:21
Joel Pearson 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. > 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: > http://selenium-tutorial.blogspot.co.uk/2012/10/se... Thanks Joel. I will try this. But was wondering is there anything wrong i m doing with Mechanize?
on 2013-03-16 11:27
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"?
on 2013-03-23 17:55
Joel Pearson wrote in post #1101912: > 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. Issue is resolved :). Thanks for your support.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.