CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Win32::IE::Mechanize

 



rgabor
New User

Mar 4, 2010, 2:19 PM

Post #1 of 3 (803 views)
Win32::IE::Mechanize Can't Post

Dear All,

I am new in this forum, and I hope that someone can help me figure out the following.

I am using Perl and Win32::IE::Mechanize to automate some task in my job. Before I have used WWW::Mechanize, but because of Java-scripts I had to switch.

I can successfully connect to the site, read and submit data, however I have an issue when I want to set value for Select Option.

Mechanize just cannot find the select control, so alway trow back an error.


I have straggling with this since few days, and I do not found anything yet.

This is the HTML code with the select

Code
<select ID="selectTest" onchange="DoSomething(0);">		 
<option value="">- Select Type -</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>


And this is the Perl code to set value.


Code
#!/usr/bin/perl 

use warnings;
use strict;

use Win32::IE::Mechanize;

my $mech = Win32::IE::Mechanize->new( visible => 1);
$mech->get('some_url');

$mech->form_name( 'form1' );

$mech->select( 'selectTest', '2' );


If I run this, it will trow an error saying that Select 'selectTest' not found.

Can someone help me on this please?

Many thanks.
Regards,
Gabor


rgabor
New User

Mar 4, 2010, 3:00 PM

Post #2 of 3 (799 views)
Re: [rgabor] Win32::IE::Mechanize [In reply to] Can't Post

Hello again,

So far I have found the issue.

The problem is that the Select tag having only ID but not name.

If I have this, the my code works:

Code
<select name="selectTest" ID="selectTest" onchange="DoSomething(0);" style="font-size:10px;">


I am not the one who developed the site so I cannot add name for select element.

Is there a way to call Select using ID instead of Name?

Thanks.


rgabor
New User

Mar 7, 2010, 1:55 AM

Post #3 of 3 (781 views)
Re: [rgabor] Win32::IE::Mechanize [In reply to] Can't Post

Hello All,

I see that many people have the same question while I was looking for solution on Google, however no one have the solution.

After hours/days of Mechanize analysis, I can see now that Mechanize looking for INPUT elements only by their name tag. No ID or whatsoever.

What I did actually, I have changed the source of Win32::IE::Mechanize, so now I can look for INPUT elements by their NAME or ID tag.


Code
use warnings; 
use strict;

use Win32::IE::Mechanize;
my $ie= Win32::IE::Mechanize->new( visible => 1);

#Get the url
$ie->get($url);

#Select a form by ID
$ie->form_id('form1');

# OR Select a form by NAME
$ie->form_name('form1');

#Find the SELECT element by ID
$ie->select_id('select1', '3');

#Find the SELECT element by NAME
$ie->select_NAME('select1', '3');

#And also for other INPUT elements like text
$ie->field_id('text1', 'test');

#or
$ie->field_name('text1', 'test');


So finally it works.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives