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);
}
}
}
}
}
}
|