LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using MSHTML functions for frames access in labwindows CVI which was not possible in labview

Hi,
 
i was trying to create an application  in labview for accessing a particular frame in a html page and then to access a form in that frame and submit it..
but unfortunately it was not possible in labview as IHTMLDocument2.frames gave me errorsssss..and i was trying a lot and finally decided to go for CVI..
 
any one can help me the functions for opening a browser,then select a particular frame and then login a  form in that frame(in  background)
in CVI???
 
REGARDS
vevek
0 Kudos
Message 1 of 8
(4,842 Views)
Hi, Vevek.

I've found an example program that displays the number of frames on a given web page. (The C and UIR files are attached.) To get the frames themselves, see line 75.

Once you've gotten the frames, accessing the form data shouldn't be too difficult. There's a nice LabVIEW screenshot here that demonstrates the process. And although you're not writing this in LabVIEW, all the invoke nodes with IHTMLElement calls map directly over to the corresponding CVI calls.

Good luck!
Sarah K.
Search PME
National Instruments
0 Kudos
Message 2 of 8
(4,814 Views)

Hi Sarah,

Thanks for the reply..

I tried accessing frames in CVI and then the forms in the particular frame...Mr. Andy(Application engineer) supported me a lot...i have the following problem in CVI which i have listed:

 I  got errors in IHTMLElementcollection.item function in CVI..

below is the definations and functions i used:

    HRESULT status;
    VARIANT vCStr;
    VARIANT element;
    static MSHTMLObj_IHTMLFramesCollection2 pFramesCol;
    static MSHTMLObj_IHTMLElementCollection formsHandle;
    static MSHTMLObj_IHTMLDocument2 doc;
    static CAObjHandle pHandle;

    MSHTML_IHTMLDocument2Getframes (docHandle, NULL, &framesHandle);
    MSHTML_IHTMLFramesCollection2Getlength (framesHandle, NULL, &numFrames);
 
 
    status = CA_VariantSetCString (&vCStr, "FRAME NAME");
    HTML_IHTMLFramesCollection2item (framesHandle, NULL, vCStr, &vCStr1);

    
    status = MSHTML_IHTMLWindow2Getframes (framesHandle,NULL,&pFramesCol);
   
    status = MSHTML_IHTMLWindow2Getdocument (framesHandle,NULL , &doc);
                                              
    status = MSHTML_IHTMLDocument2Getforms (doc, NULL, &formsHandle);
   
    status = CA_VariantSetCString (&element, "FORM NAME");
   
    status = MSHTML_IHTMLElementCollectionitem(formsHandle,NULL,element,CA_DEFAULT_VAL, &pHandle);

I implemented the above code from the following ex:(for getting a reference to the frame document)

// Assume pWin is a valid IHTMLWindow interface pointer for the main window
VARIANT frameRequested;
VARIANT frameOut;
IHTMLFramesCollection2* pFramesCol;
IHTMLWindow2* pRightFrameWindow;
IHTMLDocument2* pRightDoc;
frameRequested.vt = VT_BSTR;
frameRequested.bstrVal = L"rightframe";
hr = pWin->get_frames(&pFramesCol);
hr = pFramesCol->item(&frameRequested, &frameOut);
hr = frameOut.pdispVal->QueryInterface(IID_IHTMLWindow2, (void**)&pRightFrameWindow);
hr = pRightFrameWindow->get_document(&pRightDoc);

i checked the status and the handles in debug mode..and everything was ok except the MSHTML_IHTMLElementCollectionitem

function in which pHandle was "zero"..means no elements were collected..
i also tried in CVI, the google eg(given by Andy for searching in google)which was posted in labview
 
 
status = SHDocVw_IWebBrowser2GetDocument (webHandle, NULL, &docHandle);
status = MSHTML_IHTMLDocument2Getforms (docHandle, NULL, &formsHandle);
status = CA_VariantSetCString (&element, "f");  
status = MSHTML_IHTMLElementCollectionitem(formsHandle,NULL,element,CA_DEFAULT_VAL, &pHandle);
 
[After collecting the element we just press submit button]
here also pHandle was zero...
Could you please clarify me whether i am in the right way or not...?? and share an example in CVI enviornment..and also check if the implementation for the frames are correct?[in debug mode all all the handles except pHandle for element collection was getting collected properly]
 
awaiting your reply!!
 
Regards
Vevek
0 Kudos
Message 3 of 8
(4,808 Views)

Hi Vevek,

 

I don't know if you received this very useful attachment from Sarah or not. It’s a great example using the Microsoft HTML Object Library. This should help give you ideas and assist you in building your application.

 

Hope this helps!

 

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 4 of 8
(4,778 Views)

Hi Jonathan,

Thanks for the code. But it was already shared by Andy. In the code the number of frames in a particular page was displayed but for me

i need to go a form in a particular frame in a page..I have written the code but had problems in IHTMLElementcollection.items functions

which i have mentioned in the previous mail in detail..and i need to know whether the functions is implmented correctly or not!!and also the code..

Andy has previously implemented an ex in labview for search in google(doesn't involve frames but only forms)

i tried it in CVI but got some problems in IHTMLElementcollection.items..functions

please let me know ...the results

i am trying the same in VC++ also..

regards

vevek

0 Kudos
Message 5 of 8
(4,775 Views)

Hi vevek,

 

I have been looking at your code as well as fooling around with the code I sent you. I am know getting the same pHandle return value you were, which apparently according to Microsoft’s website indicates the element was not found and the call was not successful. I believe we are calling the functions properly, but perhaps are missing something basic in terms of the correct flow of using these function calls.

 

It appears now that we heading into deep Microsoft territory. Below is the main link on Microsoft's website to the ElementCollection object. From here you can view the item method, learn about the correct parameters (such as the name which needs to be categorized under the all collection), and view much more information. 

 

IHTMLElementCollection Interface

 

I would suggest taking a look around at these documents as they seem to provide great references into the functions you are trying to use. If after looking at these documents you are still having trouble, let us know. Also, if you do have some trouble, tell us which webpage you are testing the code on so we can be on the same page.    

 

Hope this helps!

 

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 6 of 8
(4,754 Views)

hi,

i know i am replying to this thread after a long time.. but i am having the same problem with frames in CVI.

1.I used IE activeX.

2. i got document IUnknown interface pointer from the ie Handle.

SHDocVw_GetProperty (ieHandle, 0, SHDocVw_IWebBrowser2Document, CAVT_UNKNOWN, &pUnk);

3.i got the document object from interface pointer

status=pUnk->lpVtbl->QueryInterface (pUnk,&IID_IHTMLDocument2, (void *)&document);

4.i got frames collection after that.

document->lpVtbl->get_frames(document,&pElem);  

5. i was able to get the no of frames after that

     pElem->lpVtbl->get_length(pElem,&leng);  

6.I got the document object for the IHTMLWindow2

    VARIANT ci,cl;

    IHTMLWindow2 pWindow;

     ci.n1.n2.vt=VT_UINT;
     ci.n1.n2.n3.lVal=i;
     pElem->lpVtbl->item(pElem,&ci,&cl);
    status=cl.n1.n2.n3.pdispVal->lpVtbl->QueryInterface(cl.n1.n2.n3.pdispVal,&IID_IHTMLWindow2,(LPVOID*)&pWindow);
    status=pWindow->lpVtbl->get_document(pWindow,(void *)&document1);

After this step, i tried to iterate throug the frames.i success fully went through the first frame which is 'MAIN'

but i was not able to get the document object for the second frame.i am getting the same document object again and again.

i dont get what i am doing wrong.

regards,

Radha R

0 Kudos
Message 7 of 8
(4,569 Views)
Hi, Radha.

I'm a little confused as to whether you're having one problem or several. Could you please send me a small version of your code that demonstrates this behavior (along with a web page or URL I can use to test it out)? Once I take a look and test it out, I should be able to get a more firm grasp of the specific problem you're encountering.

Thanks! Have a nice evening.
Sarah K.
Search PME
National Instruments
0 Kudos
Message 8 of 8
(4,550 Views)