Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use WWW::Mechanize to check a radio box?

I am writing a Perl script to test certain parts of my webpage as I make changes to it. Using the WWW::Mechanize class, how can I select a radio box and submit a form?

like image 774
jamesatha Avatar asked Sep 23 '10 20:09

jamesatha


People also ask

Can we use checkbox as radio button?

Both are commonly used together on forms to select options from a list. However, a radio button is a circle with a dot inside, while a checkbox is a square with a checkmark inside—two different visual cues. Some might say that their functions are different, so they should look different.

How can I check if a Radiobutton is selected?

To find the selected radio button, you follow these steps: Select all radio buttons by using a DOM method such as querySelectorAll() method. Get the checked property of the radio button. If the checked property is true , the radio button is checked; otherwise, it is unchecked.

How do I check if a radio is selected in HTML?

Use document. getElementById('id'). checked method to check whether the element with selected id is check or not.


1 Answers

What have you tried already? Did you check the WWW::Mechanize docs?

To set a field:

$mech->set_fields('radio_group_name' => 'option');

Remember, radio buttons are just instructions to the browser on how to interact with the form widget. Ultimately, it's all just fields and values you send to the web server.

To submit a form, you use one of these methods, depending on what you are trying to do:

$mech->click_button( ... );
$mech->submit();
$mech->submit_form( ... );

It does look like there's a ticket in Google Code to provide some better examples though.

like image 88
brian d foy Avatar answered Oct 22 '22 17:10

brian d foy