Solved

IHTML submit page

Posted on 2002-03-05
14
404 Views
Last Modified: 2007-11-27
Good-day,

I am writing an MFC C++ application that interacts with a specific web page.  I would like to create a dialog button in MFC that will 'click' on the 'submit' button on the web page.  I am using Microsoft's activeX Web control to load the page.

I am able to click on other button type controls on the web page using IHTMLElementPtr::click, but I could not access the web page's 'submit'or 'go' buttons. They don't seem to have an ID associated with them.

If you could give and example by demonstrating the code that would capturing the 'search' button on the 'Yahoo' page, that would be great...
0
Comment
Question by:PastorDwayne
  • 8
  • 6
14 Comments
 
LVL 1

Expert Comment

by:madface
ID: 6843236
use the submit function inside IHTMLFormElement
that will work
0
 
LVL 1

Expert Comment

by:madface
ID: 6843298

you do it the same as  you would with a client side script  ie  javascript
example code
assume p_HtmlDoc is of type IHTMLDocument2

IHTMLElementCollection* p_eles = NULL;
IHTMLFormsElement* p_formEle = NULL;
pHtmlDoc->get_forms(&p_eles);

//iteratatet through  the collection untill you find the
//form.  On yahoo i think  there  is only  1 form so it
//be at position 0
//once its found do the following


p_formEle.submit();

//done


0
 

Author Comment

by:PastorDwayne
ID: 6843353
I seem to be getting an error when I try to complie this

"error C2228: left of '.submit' must have class/struct/union type"

Here is the code I'm using:
{
MSHTML::IHTMLDocument2Ptr pDoc= m_ctrBrowser.GetDocument();
MSHTML::IHTMLElementCollectionPtr pAllElems= pDoc->all;

MSHTML::IHTMLElementCollection* p_eles = NULL;
MSHTML::IHTMLFormElement* p_formEle = NULL;
pDoc->get_forms(&p_eles);

p_formEle.submit();

}
were m_ctrBrowser is the ActiveX web control


Do you see any problems that would cause this error?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:PastorDwayne
ID: 6843386
I have now changed p_formEle.submit(); to p_formEle->submit(); thinking that this was the problem.

It is able to compile now, but it doesn't submit the form.
Any suggestions?
0
 
LVL 1

Expert Comment

by:madface
ID: 6843664

Sorry i should have been more clear.
the problem is that  p_formEle  is still NULL
do this

//we have to make a new collections for the forms
IHTMLElementCollection formEles = NULL;

_variant_t tagName("FORM");
p_ele->tags(tagName, &formEles);



//since we know there is only 1 form on the page we know
//its in the 0 index position

_variant_t index(0);
formEles->item(index, index, &p_formEle);
//now p_formEle is set and is able to use

//check to see if we do have the form
if(!p_formEle)
    {
    //error code here
    }
p_formEle.submit();

i havent tried any of this code in my compiler so there my  be compiler errors.
0
 
LVL 1

Expert Comment

by:madface
ID: 6843731
oops last line should be
sorry thats twice now
p_formEle->submit();
0
 

Author Comment

by:PastorDwayne
ID: 6843755
I have tried to work with this code, but have had no luck.  After I fixed the compile errors, It would crash the program when it was executed.

I wonder if there are any more suggestions on how to do this?

thanks very much.
0
 
LVL 1

Expert Comment

by:madface
ID: 6844912
ok whole code  all over again i just did this in MFC and it worked flawlessly



pHtmlDoc = myWebBrowser.GetDocument();

IHTMLElementCollection* p_eles = NULL;
IHTMLFormsElement* p_formEle = NULL;
pHtmlDoc->get_forms(&p_eles);

_variant_t index((LONG)0);
p_eles->item(index, index, &p_formEle);

p_formEle->submit();


good luck
0
 
LVL 1

Expert Comment

by:madface
ID: 6849865
sorry if the first two didnt work
i assumed you used HTML Dom and knew how to get elements in the Dom
0
 

Author Comment

by:PastorDwayne
ID: 6853593
madface,

Everthing seems to compile O.K except for the line:

p_eles->item(index, index, &p_formEle);

the compiler returns to state that ->item does not take three paramiters.

any suggestions?

0
 
LVL 1

Expert Comment

by:madface
ID: 6853748
im using raw COM functions
so the last param is really a return value
so try this
p_formEle = p_eles->item(index, index);

are you using a  sdk  or  the #import "\path\mshtml.tlb"

if your using the  import  try  this

p_formEle->AttachDispatch(p_eles->item(index, index));

man com sucks

now one of those 2 ways should  work (knocks on wood)
0
 

Author Comment

by:PastorDwayne
ID: 6855417
madface,

I still seem to be having troubles with the one line.  Here is my situation:

I do have #import "c:\winnt\system32\mshtml.tlb" in StdAfx.h.  I have tried:
p_formEle->AttachDispatch(p_eles->item(index, index));

but it states that :"AttachDispatch' : is not a member of 'IHTMLFormElement'"

I also tried using:
p_formEle = p_eles->item(index, index);
But is states when being compiled:
"error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class  (or there is no acceptable conversion)"


Here is my code:


{
MSHTML::IHTMLDocument2Ptr pDoc= m_ctlBrowse.GetDocument();
MSHTML::IHTMLElementCollection* p_eles = NULL;
MSHTML::IHTMLFormElement* p_formEle = NULL;
pDoc->get_forms(&p_eles);
_variant_t index((LONG)0);

p_formEle->AttachDispatch(p_eles->item(index, index));
// p_formEle = p_eles->item(index, index); //or this line

p_formEle->submit();    
}


Do you see anything that is out of the ordinary or is a problem?

Thanks very much...
0
 
LVL 1

Accepted Solution

by:
madface earned 105 total points
ID: 6856073

change  MSHTML::IHTMLFormElement  to
MSHTML::IHTMLFormElementPtr

and use  
 p_formEle = p_eles->item(index, index);

lets cross  our fingers



0
 

Author Comment

by:PastorDwayne
ID: 6858539
madface,

I tryed this out and it works perfectly! who would have guessed...

thanks for your help...
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question