🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Help with TCppWebBrowser - Find and click a button

#485
From: mike
Date: Mon, 08 Jan 2007 14:46
160 lines
4514 bytes
Hans,

I have tested the code on my side and it does work absolutely fantastic.

I cannot thank you enough for all the help you have provided. I know you 
have spent your own personal time in looking at this for me and I appreciate 
it very much.

Again, thank you and have a wonderful day.

Mike
"Hans Galema" <notused@notused.nl> wrote in message 
news:45a240c7@newsgroups.borland.com...
> Hans Galema wrote:
>
>> That has to be done yet.
>
> OK. I got it working.
>
> void __fastcall TForm4::SpeedButton10Click(TObject *Sender)
> {
> AnsiString URL = "http://rpa.tblc.org/rpa/webauth.exe?lb=PALM";
>
> WebBrowser1->Navigate ( URL );
>
> // You have to manually fill in BorrowerID and click the
> // Login button;
>         // After that click SpeedButton13
> }
>
>
> void __fastcall TForm4::SpeedButton13Click(TObject *Sender)
> {
>   AnsiString ButtonName = "secure_exit";
>
>   if ( ! WBClickButton3 ( WebBrowser1, ButtonName ) )
> ShowMessage ( ButtonName + "\n\nbutton not clicked");
> }
>
> The code:
>
> static bool __fastcall DocClickButton2 ( TComInterface<IHTMLDocument2> 
> Doc, AnsiString ButtonName )
> {
> bool clicked = false;
>
> TComInterface<IHTMLElementCollection> All;
> Doc->get_all(&All);
>
> if( All )
> {
> TComInterface<IDispatch> Disp;
>
> All->item(TVariant(WideString(ButtonName)), TVariant(0), &Disp);
>
> if( Disp )
> {
> TComInterface<IHTMLElement> Element;
> Disp->QueryInterface(IID_IHTMLElement, (LPVOID*)&Element);
>
> if( Element )
> {
> Element->click();
>
> clicked = true;
> }
> }
> }
>
> return clicked;
> }
>
>
> int level = 0; // for testing purposes
>
> static bool __fastcall DocClickButton3 ( IHTMLDocument2 *Doc, AnsiString 
> ButtonName )
> {
>  level++;
>
> bool clicked = false;
>
> long cnt = 0;
>
> TComInterface<IHTMLFramesCollection2> Frames;
>
> Doc->get_frames(&Frames);
>
> if( Frames )
> {
> Frames->get_length(&cnt);
>
> ShowMessage ( "level: " + IntToStr ( level ) + "\n\ncnt: " + IntToStr ( 
> (int)cnt ) );
> }
>
> if ( cnt > 0 )
> {
> for(long l = 0; l < cnt; ++l)
> {
> //          TVariant IndexOrName = WideString("frame name");
> // or:
> TVariant IndexOrName = l;
> TVariant Frame;
>
> Frames->item(&IndexOrName, &Frame);
>
> if( (V_VT(&Frame) == VT_DISPATCH) && (V_DISPATCH(&Frame) != NULL) )
> {
> TComInterface<IHTMLWindow2> Window;
>
> V_DISPATCH(&Frame)->QueryInterface(IID_IHTMLWindow2,(LPVOID*)&Window);
>
> if( Window )
> {
> TComInterface<IHTMLDocument2> FrameDoc;
> Window->get_document(&FrameDoc);
>
> if( FrameDoc )
> {
> // use FrameDoc as needed ...
>
> clicked = DocClickButton3 ( FrameDoc, ButtonName );
>
> if ( clicked )
> break;
> }
> }
> }
> }
> }
> else
> clicked = DocClickButton2 ( Doc, ButtonName );
>
>  level --;
>
>   return clicked;
> }
>
>
> bool __fastcall WBClickButton3 ( TWebBrowser *WebBrowser, AnsiString 
> ButtonName )
> {
> bool clicked = false;
>
> if( WebBrowser->Document )
> {
> TComInterface<IHTMLDocument2> Doc;
> WebBrowser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&Doc);
>
> if( Doc )
> {
> clicked = DocClickButton3 ( Doc, ButtonName );
> }
> }
>
> return clicked;
> }
>
> Hans. 
Technical Details
Message-ID: <45a2593e$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <459ebec4$1@newsgroups.borland.com> <459ec5bf$1@newsgroups.borland.com> <459fbc29$2@newsgroups.borland.com> <45a02189$1@newsgroups.borland.com> <45a02ab5$1@newsgroups.borland.com> <45a0c58e$1@newsgroups.borland.com> <45a0fe8a$1@newsgroups.borland.com> <45a10643$1@newsgroups.borland.com> <45a226d9@newsgroups.borland.com> <45a235ec$1@newsgroups.borland.com> <45a240c7@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,6ed59181280548e1
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "mike" <mfbrowne@earthlink.nnet>
Newsgroups: borland.public.cppbuilder.internet.web
References: <459ebec4$1@newsgroups.borland.com> <459ec5bf$1@newsgroups.borland.com> <459fbc29$2@newsgroups.borland.com> <45a02189$1@newsgroups.borland.com> <45a02ab5$1@newsgroups.borland.com> <45a0c58e$1@newsgroups.borland.com> <45a0fe8a$1@newsgroups.borland.com> <45a10643$1@newsgroups.borland.com> <45a226d9@newsgroups.borland.com> <45a235ec$1@newsgroups.borland.com> <45a240c7@newsgroups.borland.com>
Subject: Re: Help with TCppWebBrowser - Find and click a button
Date: Mon, 8 Jan 2007 09:46:43 -0500
Lines: 162
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
NNTP-Posting-Host: 72.185.80.204
Message-ID: <45a2593e$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1168267582 72.185.80.204 (8 Jan 2007 06:46:22 -0800)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail