saran_techie has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
Here's my piece of code which is used for setting the value for a textbox used in the web application. This application uses the concept of tables for having the textboxes. I have encountered with the error "can't call method ready state with an undef value". Kindly assist.
use Win32::IEAutomation; use Win32::IEAutomation::Table; #Opening IE browser #$IE=Win32::OLE->new('InternetExplorer.Application'); $IE=Win32::IEAutomation->new(visible=>1, maximize=>1); #print "test\n"; #Opening the application by providing applicaiton's URL $IE->gotoURL("http://<url>"); #Set the value to a textbox in the login web page $IE->getTable('name':, '<tablename>')->tableCells$row,$column)->SetVal +ue('user');
Regards,
Saravanan.S

Replies are listed 'Best First'.
Re: To set values for a textbox in a Web application
by marto (Cardinal) on Feb 11, 2009 at 09:59 UTC

    Hi saran_techie,

    I have never used this module (I tend to use Win32::IE::Mechanize when doing this kind of thing), however a quick look at the documentation makes me think that your getTable call is wrong. You have $IE->getTable('name':, '<tablename>') when the documentation suggests $IE->getTable("name:", "<tablename>"). The difference being that the colon is quoted.

    This aside, are you sure you are looking to populate a table with text data, and not a text input box? Your comment preceding the getTable call, along with the actual question you have asked suggests this is the case. The setValue method "will set the value of text field or text area to the string provided".

    Double check the HTML source of the page in question, find the id or the name of the text input field for the username, and try something like:

    $ie->getTextBox('name:', "userid")->SetValue("marto");

    This should set the value of a textbox named 'userid' the value 'marto'. Please not that this us untested, I don't have a windows box handy at the moment.

    As a side note, having use strict; and use warnigns; is missing from your code also :)

    Hope this helps

    Martin

      Hi Martin,
      Thanks for your reply. I do accept that getTable call is wrong, that I've misplaced the colon, but apart from that the actual problem is that I just want to know why the error "can't call method readystate with undef value" is thrown.
      Actual Scenario:
      Our application login page has two textfileds username and password. These text fields are incorporated in tables associated with classes. I've used "getTable" of IEAutomation along with the name of the textfield "username". But still am getting the error "can't call method readystate with undef value". Again I've provided my code below. Appreciate your assistance.
      use strict; use warnings; use win32::IEAutomation; use Win32::IEAutomation::Element; use Win32::IEAutomation::Table; use Win32::IEAutomation::WinClicker; my $IE = Win32::IEAutomation->new( visible => 1, maximize => 1); $IE->gotoURL('http://url') ; $IE->WaitforDone; $IE->getTable("class:", "as_txt_logincm_font_header_normal")->getTextB +ox('name:',"txtUserName")->SetValue('user1>');
      Thank You,
      Saravanan.S

        I think you have perhaps missed the point I tried to make, where in the documentation does it say you can use getTextBox in conjunction with getTable? Why didn't you simply modify my example to match your needs?:

        $ie->getTextBox('name:', "txtUserName")->SetValue("user1");

        Is there only one text box named txtUserName on the page? The documentation states "If there are more than one object having same value for the option you are quering, then it returns first object of the collection.".

        As I mentioned previously, I have never used Win32::IEAutomation, I tend to use WWW::Mechanize (Win32::IE::Mechanize at a push) which has (IMHO) better methods for filling in forms.

        Cheers,

        Martin

Re: To set values for a textbox in a Web application
by imrags (Monk) on Feb 12, 2009 at 08:25 UTC
    I've used Win32::IEAutomation a few times...
    I feel this error occurs when the page fails to load completely
    and the other function tries to access it.
    try this:
    my $agent = Win32::IEAutomation->new(visible => 1); $agent->gotoURL($URL); $agent->getTextBox('id:',"tb")->SetValue($name); $agent->getButton('id:',"cmd")->Click(); Wait_For_Complete_Load(); sub Wait_For_Complete_Load { while($agent->{agent}->Document->readyState !~ /complete/i) { sleep(1); } }
    Check the wait_for_complete_load subroutine...
    This is from one of my scripts and i've not changed
    it to suit your purpose...but this will give u the
    general idea
    Raghu