Sagacious Monks,

I don't have access to the back end database but I have been given a username and password to log on to the Cognos reporting system.

Naturally, I have a number of issues with this system -- it doesn't give the previous business day as a default unless someone's previously selected it, it doesn't give any facility for emailing or saving certain reports, and I can't alter parameters without physically opening the thing up and typing them in.

This is most annoying.

I'd like to use WWW::Mechanize or some other device to log in and perform some tasks, particularly getting and saving reports. However, I encounter errors on trying to log in.

I've looked at the source, and I know my username and password are correct. Here's the simple test code I've tried:
#! perl -w use strict; use WWW::Mechanize; my $url = 'http://crnprdweb/CRN/cgi-bin/cognos.cgi?b_action=xts.run&m= +portal/main.xts'; my $mech = WWW::Mechanize->new(); $mech->get( $url ); print $mech->status, "\n"; print $mech->success; my $content = $mech->content; $mech->submit_form( form_number =>1, fields => { CAMUsername => 'blahuser', CAMPassword => 'blahpassword', } ); $content = $mech->content; print $content;
Here are my errors. Notice I changed to use the form number instead of the name on discovering that didn't work. Commenting out the submit, I still get a status of 401 -- Unauthorized, though I'm just trying to get the base page.
H:\script>perl mechtest.pl 401 There is no form named "pform" at mechtest.pl line 12 Can't call method "value" on an undefined value at C:/Perl/site/lib/WW +W/Mechaniz e.pm line 571. H:\script>perl mechtest.pl 401 There is no form numbered 1 at mechtest.pl line 12 Can't call method "value" on an undefined value at C:/Perl/site/lib/WW +W/Mechaniz e.pm line 571.
I'm wondering if this is specific to Cognos, and whether I should try automating IE instead. HTML and javascript isn't exactly my strength (I can scratch out a simple page of html, but I don't work with it extensively), so I've considered that it may be the nature of the submit button as well (though WWW::Mechanize indicates its "submit" function doesn't actually rely on the button, it's not clear to me what it does rely on). So, here's the code for that button (sans the actual function code).
<a href="javascript:doSubmit()" onblur="javascript:setFocus('')" onfoc +us="javascript:setFocus('ok')" onmouseover="window.status='';return t +rue;" onmouseout="window.status='';return true;"><span class="command +ButtonActive">OK</span></a>
Can anyone give me some advice on how to get around these errors, or whether I'd be better advised to automate the browser instead of using Mech? Obviously I haven't gotten very far yet, and don't know what other errors I might encounter.

In reply to WWW::Mechanize Cognos web by SamCG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.