🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Help with TCppWebBrowser - Find and click a button

#480
From: Hans Galema
Date: Mon, 08 Jan 2007 13:00
143 lines
4136 bytes
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: <45a240c7@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!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>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,6ed59181280548e1
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Mon, 08 Jan 2007 14:00:19 +0100
From: Hans Galema <notused@notused.nl>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.web
Subject: Re: Help with TCppWebBrowser - Find and click a button
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>
In-Reply-To: <45a235ec$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 145.98.201.248
Message-ID: <45a240c7@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1168261319 145.98.201.248 (8 Jan 2007 05:01:59 -0800)
Lines: 143
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail