Help, Please: Can't Get a Hold of <input type=button ...>
Listers,
I am new to WWW::Mechanize, and have gotten it to mechanize alot of
point and click stuff, so it's really great. But I cam across a page
that refuses to yeild. I hope someone can help.
I hit a page on the FDIC website that allows me to download Bank
Performance Reports, so-called "Call Reports." I can fill in the fields
on the page, but the button that kicks off the file transfer is
generated by an HTML tag like this:
<input type="button" value="Export" onclick="FormSubmit(this.form);">
I have tried to click it three ways, by specifying the value, the
number, and by just invoking $mech->submit() after selecting into the
form. None of these worked:
1. $mech->click_button(value => 'Export') yeilds "Can't call method
'header' on undefined value." error.
2. $mech->click_button(number => 1) yeilds "Can't call method 'click' on
undefined value." error.
3. $mech->submit() yeilds no error, but no content either.
I poked around in the code, and it looks like HTML::Form is parsing the
<input type="button" ...> tag as a type HTML::Form::IgnoreInput, which
it does very effectively. Apparently, it only counts a <input
type="submit" ...> tag as a button.
Is this right? I'm no HTML expert, but my 1998 O'Reilly book on HTML,
covering HTML 4.0 states that <input type="button" ...> is a synonym for
<button ...>. I would think that HTML::Forms would allow 'click' on the
two variants of button, not just <input type="submit" ...>.
Am I missing something?
My version of HTML::Forms has a version number of 1.44.
I would greatly appreciate any guru-tude you can throw my way.
Thanks.
--
Daniel E. Doherty <ded [at] jupiter.ddoherty.net>
Re: Help, Please: Can't Get a Hold of <input type=button ...>
On Wed, 8 Sep 2004, Daniel E. Doherty wrote:
> I hit a page on the FDIC website that allows me to download Bank
> Performance Reports, so-called "Call Reports." I can fill in the fields
> on the page, but the button that kicks off the file transfer is
> generated by an HTML tag like this:
>
> <input type="button" value="Export" onclick="FormSubmit(this.form);">
[...]
> Is this right? I'm no HTML expert, but my 1998 O'Reilly book on HTML,
> covering HTML 4.0 states that <input type="button" ...> is a synonym for
> <button ...>.
No, they're not synonymous. Quoting from my FAQ on my Python module based
on HTML::Forms (see second bullet point -- your callback JavaScript
function is FormSubmit()):
http://wwwsearch.sourceforge.net/ClientForm/#faq
Why does .click()ing on a button not work for me?
- Clicking on a RESET button doesn't do anything, by design - this is a
library for web automation, not an interactive browser. Even in an
interactive browser, clicking on RESET sends nothing to the server, so
there is little point in having .click() do anything special here.
- Clicking on a BUTTON TYPE=BUTTON doesn't do anything either, also by
design. This time, the reason is that that BUTTON is only in the HTML
standard so that one can attach callbacks to its events. The callbacks are
functions in SCRIPT elements (such as Javascript) embedded in the HTML,
and their execution may result in information getting sent back to the
server. ClientForm, however, knows nothing about these callbacks, so it
can't do anything useful with a click on a BUTTON whose type is BUTTON.
- Generally, embedded script may be messing things up in all kinds of ways.
See the answer to the next question.
John
Re: Help, Please: Can't Get a Hold of <input type=button ...>
On Sun, 2004-09-12 at 07:32, John J Lee wrote:
> On Wed, 8 Sep 2004, Daniel E. Doherty wrote:
>
> > I hit a page on the FDIC website that allows me to download Bank
> > Performance Reports, so-called "Call Reports." I can fill in the fields
> > on the page, but the button that kicks off the file transfer is
> > generated by an HTML tag like this:
> >
> > <input type="button" value="Export" onclick="FormSubmit(this.form);">
> [...]
> > Is this right? I'm no HTML expert, but my 1998 O'Reilly book on HTML,
> > covering HTML 4.0 states that <input type="button" ...> is a synonym for
> > <button ...>.
>
> No, they're not synonymous. Quoting from my FAQ on my Python module based
> on HTML::Forms (see second bullet point -- your callback JavaScript
> function is FormSubmit()):
>
> http://wwwsearch.sourceforge.net/ClientForm/#faq
>
> Why does .click()ing on a button not work for me?
>
> - Clicking on a RESET button doesn't do anything, by design - this is a
> library for web automation, not an interactive browser. Even in an
> interactive browser, clicking on RESET sends nothing to the server, so
> there is little point in having .click() do anything special here.
>
> - Clicking on a BUTTON TYPE=BUTTON doesn't do anything either, also by
> design. This time, the reason is that that BUTTON is only in the HTML
> standard so that one can attach callbacks to its events. The callbacks are
> functions in SCRIPT elements (such as Javascript) embedded in the HTML,
> and their execution may result in information getting sent back to the
> server. ClientForm, however, knows nothing about these callbacks, so it
> can't do anything useful with a click on a BUTTON whose type is BUTTON.
>
> - Generally, embedded script may be messing things up in all kinds of ways.
> See the answer to the next question.
>
Thanks.
Here is the javascript function that gets invoked:
function FormSubmit(objForm)
{
var strVersion = new String(navigator.appVersion);
var arrVersion = strVersion.split(" ");
var intVersion = new Number(arrVersion[0]);
objForm.BrowserName.value = navigator.appName;
if (navigator.appName == "Netscape")
{
//alert("here");
objForm.action = "NSPrint.asp";
}
objForm.submit();
}
One of the solutions you recommend is to do in python what the script
does. It looks to me like this script just submits the form or prints
for Navigator (though I don't know much about javascript). It would
seem, then, that I ought to be able to do $mech->submit(). But when I
do that, I get empty content in the response, though response is OK and
the content-type is "application/textfile" and the content-disposition
is "inline; filename=Cert4619_P".
I am expecting a tab-delimited file. I just can't get it to move the
file.
Any thoughts?
>
> John
--
Dan Doherty
ded-law [at] ddoherty.net
913.402.7336 (Voice)
913.402.7336 (Fax)
913.488.3342 (Mobile)
Re: Help, Please: Can't Get a Hold of <input type=button ...>
On Mon, 13 Sep 2004, Daniel E. Doherty wrote:
[...]
> Here is the javascript function that gets invoked:
> function FormSubmit(objForm)
> {
> var strVersion = new String(navigator.appVersion);
> var arrVersion = strVersion.split(" ");
> var intVersion = new Number(arrVersion[0]);
>
> objForm.BrowserName.value = navigator.appName;
> if (navigator.appName == "Netscape")
> {
> //alert("here");
> objForm.action = "NSPrint.asp";
> }
> objForm.submit();
> }
>
> One of the solutions you recommend is to do in python what the script
> does. It looks to me like this script just submits the form or prints
> for Navigator (though I don't know much about javascript). It would
[...]
The last line submits the form. The rest of it doesn't <wink>.
For example, objForm.action = "blah" sets the form element's action
attribute to "blah", thus causing objForm.submit() to submit to a
different URL. Google for "HTML 4.01 spec", and read the documentation
for the Form element's action attribute. Then try looking at the HTML
that contains the JavaScript function above, and figure out what
objForm.BrowserName.value = "whatever" does (search for "BrowserName" in
the HTML).
John