w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
"element does not exist in cache" error upon radio button select using mechanize::phantomjs

mechanize requires you to select the form before you can set the form fields. This can be done with a variety of functions such as

  • $mech->form_name( $name [, %options] )
  • $mech->form_id( $id [, %options] )
  • $mech->form_number( $number [, %options] )
  • $mech->form_with_fields( [$options], @fields )

Taken from here.

If this doesn't work, you can always run some custom code in the page context to change the fields. For radio boxes this would look like this:

$mech->eval(<<'JS', $i);
[name='radioButtonName']")[arguments[0]].checked = true;

Although, this only changes the property of the radio button and in most cases this is enough. But sometimes there are event handlers on the DOM elements which will not be triggered in this case.

An alternative would be to actually use $mech->click( $name [,$x ,$y] ) to click on the radio button and trigger all necessary events.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.