can't use www:mech set_fields for a select field.

------=_NextPart_000_010E_01C4E113.74752900
Content-Type: text/plain;
charset="iso-8859-9"
Content-Transfer-Encoding: 7bit



Hi there,



Someone please help me with this.



I'm trying to select value from two select boxes and submit the form. But
the select boxes are filled via javascript codes. The source code looks like
this:



................

<select name="productSearch1:lbCategories" size="10" multiple="multiple"
id="productSearch1_lbCategories" class="urun_arama_field"
OnChange="lbCategories_onChange();" style="width:150px;">

</select></td>

<td class="urun_arama_back2" align="center"> 

<select name="productSearch1:lbSubcategories" size="10" multiple="multiple"
id="productSearch1_lbSubcategories" class="urun_arama_field"
OnChange="lbSubcategories_onChange();" style="width:150px;">

..............

............

<script language="javascript">

var
lbCategories=window.top.document.getElementById("ProductSear ch1_lbCategories
");

var
lbSubcategories=window.top.document.getElementById("ProductS earch1_lbSubcate
gories");

var lbBrands=window.top.document.getElementById("ProductSearch1_ lbBrand");



</script>





I know what values to send via this select boxes but unfortunately I can't
set them to those values.



I tried:



$mech -> form_name(Form1);

$mech -> select('productSearch1:lbCategories', $_[0]);

$mech -> select('productSearch1:lbSubcategories', $_[1]);

$mech -> submit();



which yields

input 'productSearch1:lbCategories' not found

input 'productSearch1:lbSubcategories' not found





and



$mech -> form_name(Form1);

$mech -> set_fields('productSearch1:lbCategories' => $_[0],
'productSearch1:lbSubcategories' => $_[1],);

$mech -> submit();



which yields

No such field 'productSearch1:lbSubcategories'



I'm not sure if I can use set_visible.



I came across the same problem in another site but then I solved my problem
by writing the values with the URL. (.../search.aspx?category=XYZ&brand=XYZ)
but this time the form method is POST. So that trick doesn't work:-(



Anyone have any idea how to send these input values? Thanks in advance.












------=_NextPart_000_010E_01C4E113.74752900--
burcu [ Mo, 13 Dezember 2004 11:58 ] [ ID #534320 ]

Re: can't use www:mech set_fields for a select field.

Hi Burcu.

I wish Mechanize could handle javascript. It would make some things so
much easier!

Based on your description, it sounds like either the input field is not
named what you think it is, or for some reason, HTML::Form doesn't want
you to address the field by name (are there limitations to the
characters allowed in a form name?).

You can use $form = $mech->form_name($name) to manipulate the form
object directly. This gives you more methods than Mechanize supports.

I would try the $input = $form->find_input method to scan through the
input fields, then you can determine what names HTML::Form thinks are
present or use the $input->value($new_value) method to set the field
without using the name.

Hope this helps.

Best regards

Peter


>
>
peter.stevens [ Mi, 15 Dezember 2004 12:15 ] [ ID #538257 ]

RE: can't use www:mech set_fields for a select field.

Hi Peter,

Thank you for the help. I just had time to try it, was working on other
stuff.

Anyway, find_input doesn't work either. My code :

$form =3D $mech -> form_name(Form1);
[at] inputs =3D $form -> find_input();
foreach $input ( [at] inputs) {
print ">>$input->{name}<<\n";
}

only prints the input text boxes and selects that has option tags in
between. The input select box I try to use is

< select name=3D"productSearch1:lbCategories" size=3D"10" =
multiple=3D"multiple"
id=3D"productSearch1_lbCategories" class=3D"urun_arama_field"
OnChange=3D"lbCategories_onChange();" style=3D"width:150px;" >
< / select >

So find_input doesn't get it:(

I can't use $input->value($new_value) on this undefined input.

I think I'll give up using mech and do my job manually for this site:)

Thank you anyway.

B.



-----Original Message-----
From: Peter Stevens [mailto:peter.stevens [at] ch-open.ch]
Sent: Wednesday, December 15, 2004 1:16 PM
To: Burcu Gümü=FE Demokan
Cc: libwww [at] perl.org
Subject: Re: can't use www:mech set_fields for a select field.

Hi Burcu.

I wish Mechanize could handle javascript. It would make some things so
much easier!

Based on your description, it sounds like either the input field is not
named what you think it is, or for some reason, HTML::Form doesn't want
you to address the field by name (are there limitations to the
characters allowed in a form name?).

You can use $form =3D $mech->form_name($name) to manipulate the form
object directly. This gives you more methods than Mechanize supports.

I would try the $input =3D $form->find_input method to scan through the
input fields, then you can determine what names HTML::Form thinks are
present or use the $input->value($new_value) method to set the field
without using the name.

Hope this helps.

Best regards

Peter


>
>
burcu [ Mo, 20 Dezember 2004 14:28 ] [ ID #545490 ]
Perl » perl.libwww » can't use www:mech set_fields for a select field.

Vorheriges Thema: NTLM question?
Nächstes Thema: Possible problem with RobotRules?