[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

TCppWebBrowser  Click button on page

Asked by TopKah in C++ Builder, Microsoft Visual C++, Delphi IDE

Tags: WebBrowser IHTMLDocument2, TCppWebBrowser

Okay I have managed  to obtain the IHTMLDocument2 from the Web Browser and click a button,  but after clicking the button I got a confirmation message coming from a script and I have to response to .
How can I response or simulate the click of this message or execute it on the page with response value.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
 This is the web form source :
input type="submit" name="Button1" value="LogOut"
 onclick="return confirm(" Are you Sure you want to logout ?");" id="Button1" 
 
 
 
and this is my source code to press the button :
 
void __fastcall TForm1::Button3Click(TObject *Sender)
{
	PresstheButton("Button1", 0);
}
 
void PresstheButton(String FieldName, int Option)
{
	// Obtain the IHTMLDocument2 from the Web Browser
	TComInterface<IHTMLDocument2>PageDoc;
	Form1->CppWebBrowser1->Document->QueryInterface
		(IID_IHTMLDocument2, (LPVOID*) & PageDoc);
 
	if (PageDoc)
	{
		// Obtain a list of all the elements
		TComInterface<IHTMLElementCollection>All;
		PageDoc->get_all(&All);
		if (All)
		{
			// Get the first element i.e. TVariant(0) with the given FieldName
			TComInterface<IDispatch>Disp;
			All->item(TVariant(WideString(FieldName)), TVariant(Option), &Disp);
 
			if (Disp)
			{
				TComInterface<IHTMLInputElement>InputElement;
				Disp->QueryInterface(IID_IHTMLInputElement, (LPVOID*)
					& InputElement);
 
				if (InputElement)
				{
					// Check the Button 
					InputElement->put_checked(1);
					DISPID idMethod[1];
					LPOLESTR FnName[1] =
					{
						L"OnClick"
					};
					if (InputElement->GetIDsOfNames(IID_NULL, FnName, 1,
							LOCALE_SYSTEM_DEFAULT, idMethod) == 0)
					{
						DISPPARAMS dpNoArgs =
						{
							NULL, NULL, 0, 0
						};
						InputElement->Invoke(idMethod[0], IID_NULL,
							LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dpNoArgs,
							NULL, NULL, NULL);
					}
				}
			}
		}
	}
}
[+][-]10/30/09 03:48 PM, ID: 25707259Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 07:00 AM, ID: 25729536Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625