Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simulating Click on a Web Page

Status
Not open for further replies.

OneSource

Programmer
Jun 18, 2002
22
US
Hi.

I'm trying to simulate a click on a web page using Visual C++. I'm able to extract the contents of the page and get all the elements, but I can't get the click to work when the command (push) button on the web page can have a couple of values. Here's a snippet of my code:

Code:
// Set the name and index of the
// command button on the web page.
varID.SetString("DoThis");
varIdx.intVal = 0;

// Get all elements on the web page.
pNewDoc->get_all(&pElemColl);

hr = pElemColl->item(varID, varIdx, &pElemDisp);

if(SUCCEEDED(hr))
{
	hr = pElemDisp->QueryInterface(IID_IHTMLElement, (void**)&pElem);

	if(SUCCEEDED(hr))
	{
		// Obtained element with ID of "DoThis".
		// Here is where I need to assign a Value to DoThis
		// If it helps, in VB, the syntax is just DoThis.Value = "GetName"
		// After the value is assigned, I want to click the DoThis element.
		pElem->click();
		pElem->Release();
	}
}
I'm sure this is probably simple, put I need some help with it.

Thanks in advance.
 
To do the equaivalent of a VB: Document.All.Item("DoThis").Value = "GetName", you can do this with pElem

CComBSTR bstrNewValue;
bstrNewValue = L"GetName";

VARIANT varNewValue;
VariantInit(&varNewValue);
V_VT(&varNewValue) = VT_BSTR;
V_BSTR(&varNewValue) = bstrNewValue;

pElem->setAttribute(L"value",varNewValue, 0);
pElem->Click;

I believe you have to release the V_BSTR like this when you are done but I have seen some code where it is not done.

SysFreeString(V_BSTR(&varNewValue));

Let me know if that works for you.

-Tim
 
Hi! Onesource...

I have been trying to list all the controls on the webpage but this seems to evade me a bit...

Can you please kindly pass on the code to do it.

Thanks in advance,
Jayashree Rama Rao
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top