🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.web
5 messages
5 total messages Started by Mitch McInelly Fri, 25 Feb 2005 20:47
Clicking an HTMLInputButton with C++Builder
#1287
Author: Mitch McInelly
Date: Fri, 25 Feb 2005 20:47
71 lines
3351 bytes
I am writing an app that prefills applications on the web with information 
stored in my software.   I now understand that I must use the Microsoft DOM 
to achieve my goals.

Now I am trying to get my app to click a submit button on a form after I 
have prefilled the data.  The HTML for the button looks like...


<TD align=right vAlign=top><input type=image alt=Submit height=17
                        src="images/button_submit.gif"
                        width=42 onClick="submitForm();"></TD>

And my code looks like this (with apologies to Remy):

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

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

                    All->item(item, index, &Disp);
                    if( Disp )
                    {
                        TComInterface<IHTMLInputButtonElement> ButtonInput; 
// I've also tried HTMLButtonElement here..
                        Disp->QueryInterface(IID_IHTMLInputButtonElement,(LPVOID*)&ButtonInput);

                        if( ButtonInput )
                        {ShowMessage("Button Found");

                        // Code goes here to make sure Button is of type 
Submit

                         TComInterface<IHTMLElement> Element;
                         Disp->QueryInterface(IID_IHTMLElement,(LPVOID*)&Element); 
// HTMLInputButtonElement has no click() method so I have to revert 
//   back to HTMLElement???

                         if(Element)
                         {Element->click();}


                        }

                    }
                }

           }
        }

}

For some reason the button is never found (the ShowMessage never fires).  Am 
I using the wrong element?

Thanks for looking.

Mitch McInelly
Re: Clicking an HTMLInputButton with C++Builder
#1289
Author: Hans Galema
Date: Fri, 25 Feb 2005 21:29
12 lines
1350 bytes
Mitch McInelly wrote:

> <TD align=right vAlign=top><input type=image alt=Submit height=17
>                         src="images/button_submit.gif"

>                         TComInterface<IHTMLInputButtonElement> ButtonInput; 

But you defined your input element of type image. Not of type button.

So I think you should use <IHTMLInputImageElement>. If there is.

Hans.
Re: Clicking an HTMLInputButton with C++Builder
#1290
Author: 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
Re: Clicking an HTMLInputButton with C++Builder
#1291
Author: Mitch McInelly
Date: Fri, 25 Feb 2005 22:32
71 lines
3413 bytes
Again, thank you.  It works perfectly!



"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:421f9ac7$1@newsgroups.borland.com...
>
> "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
>
> 
Re: Clicking an HTMLInputButton with C++Builder
#1292
Author: Mitch McInelly
Date: Fri, 25 Feb 2005 22:33
19 lines
1652 bytes
Yes, of course.  Just cause it looks like a button doesn't mean it's a 
button.  Very stupid of me.


"Hans Galema" <notused@notused.nl> wrote in message 
news:421f98fc$1@newsgroups.borland.com...
> Mitch McInelly wrote:
>
>> <TD align=right vAlign=top><input type=image alt=Submit height=17
>>                         src="images/button_submit.gif"
>
>>                         TComInterface<IHTMLInputButtonElement> 
>> ButtonInput;
>
> But you defined your input element of type image. Not of type button.
>
> So I think you should use <IHTMLInputImageElement>. If there is.
>
> Hans. 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads