Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the WWW-Mechanize CPAN distribution.

Report information
The Basics
Id: 6100
Status: resolved
Priority: 0/
Queue: WWW-Mechanize

People
Owner: MARKSTOS [...] cpan.org
Requestors: rmeden [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.52
Fixed in: (no value)



Subject: request: find-form method
The web page I'm trying to work against doesn't label their forms. I wrote the following subroutine to find it. You may want to include a cleaned up (and probably expaneded) version in the project. Thanks for the module btw.. certainly makes some things easier. # # subroutine to search for form w/o knowing it's name # sub find_form($$) { my $mech=shift || die "find_form: mechanize object not specified"; my $name=shift || die "find_form: field name not specified"; my @forms=$mech->forms; my $form_num=0; foreach (0..$#forms) { $fn=$_ if $forms[$_]->find_input($name); } $mech->form_number($fn+1) if $fn; return $fn; }
[REDEN - Thu Apr 22 09:42:53 2004]: ooops.. use strict must not be on! Show quoted text
> my $fn=0;
Robert
[REDEN - Thu Apr 22 09:42:53 2004]: Show quoted text
> The web page I'm trying to work against doesn't label their forms. I > wrote the following subroutine to find it. You may want to include a > cleaned up (and probably expaneded) version in the project. > > Thanks for the module btw.. certainly makes some things easier. > > # > # subroutine to search for form w/o knowing it's name > # > sub find_form($$) > { > my $mech=shift || die "find_form: mechanize object not specified"; > my $name=shift || die "find_form: field name not specified"; > my @forms=$mech->forms; > my $form_num=0; > foreach (0..$#forms) > { > $fn=$_ if $forms[$_]->find_input($name); > } > $mech->form_number($fn+1) if $fn; > return $fn; > }
I think the "set_visible()" method was added to solve just this case. If that doesn't sufficiently address your needs, re-open the ticket. (But before you do, look at the two tickets that I related to this one, which both deal with enhancements to set_visible() that have been requested). Thanks for the feedback! Mark
[MARKSTOS - Tue Oct 19 21:33:18 2004]: Show quoted text
> I think the "set_visible()" method was added to solve just this case. If > that doesn't sufficiently address your needs, re-open the ticket.
set-visible is used to set unnamed fields in a form. I'm working against a web page that has multiple forms, but no form names. The suggested function allows me to find the right form using the field names. (the referenced tickets weren't really relevent) Robert
Date: Tue, 19 Oct 2004 21:26:35 -0500
From: Mark Stosberg <mark [...] summersault.com>
To: Robert_Eden via RT <bug-WWW-Mechanize [...] rt.cpan.org>
Subject: Re: [cpan #6100] request: find-form method
RT-Send-Cc:
On Tue, Oct 19, 2004 at 09:57:26PM -0400, Robert_Eden via RT wrote: Show quoted text
> > This message about WWW-Mechanize was sent to you by REDEN <REDEN@cpan.org> via rt.cpan.org > > Full context and any attached attachments can be found at: > <URL: https://rt.cpan.org/Ticket/Display.html?id=6100 > > > [MARKSTOS - Tue Oct 19 21:33:18 2004]:
> > I think the "set_visible()" method was added to solve just this case. If > > that doesn't sufficiently address your needs, re-open the ticket.
> > set-visible is used to set unnamed fields in a form.
True. It doesn't require you to know the form names, though. Show quoted text
> I'm working against a web page that has multiple forms, but no form > names. The suggested function allows me to find the right form using the > field names.
I think $mech->form_number() should work for you, then. submit_form() also has a 'form_number' option. Mark -- http://mark.stosberg.com/
[mark@summersault.com - Tue Oct 19 22:25:54 2004]: Show quoted text
> > I'm working against a web page that has multiple forms, but no form > > names. The suggested function allows me to find the right form using
> the field names. > > I think $mech->form_number() should work for you, then. >
Yes that would work. Only problem is the purpose of WEB::Mechanize is to make the script as insensitive to site changes as possible. Using form numbers (or field numbers for that matter), will break if an extra form is added later. In my code, I search all the forms for a specific field. I think that's less sensitive to site changes. Robert
Date: Wed, 20 Oct 2004 07:28:18 -0500
From: Mark Stosberg <mark [...] summersault.com>
To: Guest via RT <bug-WWW-Mechanize [...] rt.cpan.org>
CC: alias mech <www-mechanize-development [...] lists.sourceforge.net>
Subject: Re: [cpan #6100] request: find-form method
RT-Send-Cc:
On Wed, Oct 20, 2004 at 01:44:44AM -0400, Guest via RT wrote: Show quoted text
> > This message about WWW-Mechanize was sent to you by guest <> via rt.cpan.org > > Full context and any attached attachments can be found at: > <URL: https://rt.cpan.org/Ticket/Display.html?id=6100 > > > [mark@summersault.com - Tue Oct 19 22:25:54 2004]:
> > > I'm working against a web page that has multiple forms, but no form > > > names. The suggested function allows me to find the right form using
> > the field names. > > > > I think $mech->form_number() should work for you, then. > >
> > Yes that would work. Only problem is the purpose of WEB::Mechanize is > to make the script as insensitive to site changes as possible. Using > form numbers (or field numbers for that matter), will break if an extra > form is added later. > > In my code, I search all the forms for a specific field. I think that's > less sensitive to site changes.
I think this is a reasonable feature to add. Here's one way I could see it being designed: We already have two form-discovery methods: form_name form_number ########## I might go so far to to suggest we deprecate these in favor a more general purpose function "find_form", that would work like "find_link()". It would support options include name => n => number => # alias for 'n' field_name => # match the first which contains this field name. The 'number' field could be applied to others, so you can mean: "find the second form named 'foo'", or "find the second form which contain fields named 'jones'". I would use this feature myself, I think. I started putting names in our forms so I could find them with Mech. However, a lot of times the field names are unique enough that I could pick out one unique to the form I want. I have also had times were my Mech script makes because someone changed the form name thinking it wouldn't make a difference. We'll get some feedback from other Mech developers and users and come up with a solution for this. I'm CC'ing our developer list for comment. Mark -- http://mark.stosberg.com/
On Thu Apr 22 09:42:53 2004, REDEN wrote: Show quoted text
> The web page I'm trying to work against doesn't label their forms. I > wrote the following subroutine to find it. You may want to include a > cleaned up (and probably expaneded) version in the project.
A new developer release of Mech should be out soon which includes a new option to address this. Look at the Changes file for the example about submit_form( with_data => \%fields ); Feedback is welcome. Mark