🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #1290

Re: Clicking an HTMLInputButton with C++Builder

#1290
From: Remy Lebeau (TeamB)
Date: Fri, 25 Feb 2005 21:35
61 lines
2975 bytes
"Mitch McInelly" <mitch@agencysoftware.com> wrote in message
news:421f8f60$1@newsgroups.borland.com...

> Now I am trying to get my app to click a submit button on a
> form after I have prefilled the data.
<snip>
> For some reason the button is never found (the ShowMessage
> never fires).  Am I using the wrong element?

Yes.  Your form is using an image, not a button, so you should be looking
for IHTMLInputImage rather than IHTMLInputButtonElement.

Rathr than trying to click the submit button, you should instead get the
IHTMLFormElement interface for the form itself and call its submit() method.
For example:

    void __fastcall TMain::SubmitForm(void)
    {
        TComInterface<IHTMLDocument2> Doc;
        Browser->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&Doc);
        if( Doc )
        {
            TComInterface<IHTMLElementCollection> Forms;
            Doc->get_forms(&Forms);
            if( Forms )
            {
                long count = 0;
                Forms->get_length(&count);

                for(long x = 0; x < count; ++x)
                {
                    TVariant item = x;
                    TVariant index = 0;
                    TComInterface<IDispatch> Disp;

                    Forms->item(item, index, &Disp);
                    if( Disp )
                    {
                        TComInterface<IHTMLFormElement> Form;
                        Disp->QueryInterface(IID_IHTMLFormElement,
(LPVOID*)&Form);
                        if( Form )
                        {
                            ShowMessage("Form Found");
                            Form->submit();
                            break;
                        }
                    }
                }
            }
        }

If the page has multiple forms, it is your own responsibility to make sure
that you are submitting the proper form.  If the forms have names assigned,
you can specify the desired name rather than an index when calling
IHTMLElementCollection::item().


Gambit
Technical Details
Message-ID: <421f9ac7$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <421f8f60$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,184c4a7d124f540d
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.web
References: <421f8f60$1@newsgroups.borland.com>
Subject: Re: Clicking an HTMLInputButton with C++Builder
Date: Fri, 25 Feb 2005 13:35:54 -0800
Lines: 63
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <421f9ac7$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1109367495 68.69.17.41 (25 Feb 2005 13:38:15 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail