Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a Radio Button using Mechanize in Ruby?

i am building a crawler and i am using Mechanize. I wish to click on a radio button. How do i do that ?

Like for example there are two radio buttons say 'A' and 'B'. The website automatically selects B, but i want 'A' using Mechanize in ruby. I am also using the latest version on Mechanize.

like image 207
Kaushik Thirthappa Avatar asked Nov 11 '11 10:11

Kaushik Thirthappa


1 Answers

There are a couple of ways to do this. Probably the best would be to use the radio button's name or id:

form.radiobutton_with(:name => /b/).check

You could also do something like this:

form.radiobuttons.first.check

Which is more succinct, but more likely to break (if for instance you were to change the design of your form).

like image 198
Alex Peattie Avatar answered Sep 22 '22 20:09

Alex Peattie