 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
mike Guest
|
Posted: Sat Jan 06, 2007 3:11 am Post subject: Help with TCppWebBrowser - Find and click a button |
|
|
Hello, and Happy New Year to all.
I have a problem which I cannot seem to solve, and I do not know how to go
about it. So if someone could help I would apprciate it very much.
The problem:
I would like to programmably be able to click a button on a web page loaded
into a TCppWebBrowser. The web page has a Tree View, I believe, on the left
side and the button is located within this view. If I view the source from
within the browser the source looks like below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Links Screen</title>
<meta HTTP-EQUIV="Pragma" CONTENT="No-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="No-cache">
<meta HTTP-EQUIV="Expires" CONTENT="0">
<meta HTTP-EQUIV="last modified" CONTENT="NOW">
<script LANGUAGE="JavaScript" SRC="/rpa/default/newAuthlib.js"></script>
<script language=javascript>
if (document.layers) {
WW = innerWidth; WH = innerHeight;
captureEvents(Event.RESIZE);
onresize=function(){if
(WW!=innerWidth||WH!=innerHeight){location.reload();return 0;}}
}
</script>
<base target="feature">
</head>
<body BGCOLOR="#FFCC33" Link="#800000" vLink="#800000" aLink="#000000"
text="#000000" topmargin="0" leftmargin="0" marginheight="0"
marginwidth="0">
<table height="100%" border="0" cellspacing="0" cellpadding="14"
width="100%">
<tr>
<td valign="top"><font FACE="Arial, Verdana"><b><small>Authorized
Links</small></b></font><p><font face="Arial, Verdana" size="2">
<ul>
<script LANGUAGE="JavaScript">
<!-- Hide script from older browsers.
buildLinks();
//alert('made it');
// End of the hiding here. -->
</script>
</ul></p>
<form>
<p><input TYPE="button" NAME="secure_exit" VALUE=" Finished "
onClick="logout();"> <!--webbot bot="HTMLMarkup"
startspan --></SCRIPT><!--webbot bot="HTMLMarkup" endspan --> </font></p>
</form>
</td>
</tr>
<tr>
<td valign="bottom"><font face="Arial, Verdana" size="2"><p
align="center"><img src="/rpa/default/images/epix_logo.gif"></p></font></td>
</tr>
</table>
<!--<p><font face="Verdana" size="1">the following link is temporary...
</font></p><form action="http://subscribe.eb.com/cgi-bin/institution_rem.pl"
method="post"> <input type="hidden" name="uid" value="!@#als"><p><input
type="submit" value="Britannica"> </p></form><p> </p>-->
</body>
</html>
I would like to be able to auto click the button above or invoke the
logout() routine. I have a number of things to find this button but it does
not seem I can find it. This portion of the web page may also reside within
a frame but when I save all the frames source to a temp file this part of
the source never shows up.
So I am at a loss to figure out how to get this to work and would appreciate
any help I can get. I am not very familiar with trying to accomplish this
type of work so samples code on how to get this to work would certainly be
appreciated.
Thank you for helping if you can.
Mike |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Jan 06, 2007 3:41 am Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
"mike" <mfbrowne (AT) earthlink (DOT) nnet> wrote in message
news:459ebec4$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I would like to programmably be able to click a button on a web
page loaded into a TCppWebBrowser.
|
You need to use the DOM intefaces for that. If the button has a name,
then you can use the IHTMLDocument2::all collection to find it
quickly. Otherwise, you have to drill down the parent/child hierarchy
manually. Either way, once you locate the button, you can obtain its
IHTMLElement interface and then call its click() method.
| Quote: | The web page has a Tree View, I believe, on the left side and the
button is located within this view.
|
There is no TreeView control in HTML.
| Quote: | If I view the source from within the browser the source looks like
below: |
The only non-form button I see in that code is named "secure_exit". I
am assuming that the one you want. The code to access it would look
like this:
#include <mshtml.h>
#include <utilcls.h>
if( CppWebBrowser1->Document )
{
TComInterface<IHTMLDocument2> Doc;
CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&Doc);
if( Doc )
{
TComInterface<IHTMLElementCollection> All;
Doc->get_all(&All);
if( All )
{
TComInterface<IDispatch> Disp;
All->item(TVariant(WideString("secure_exit")),
TVariant(0), &Disp);
if( Disp )
{
TComInterface<IHTMLElement> Element;
Disp->QueryInterface(IID_IHTMLElement,
(LPVOID*)&Element);
if( Element )
Element->click();
}
}
}
}
| Quote: | This portion of the web page may also reside within a frame
|
That makes a big difference. You need the IHTMLDocument2 interface
for the specific frame that you are going to search. Starting with
the top-level Document, you can use its frames collection to access
the IHTMLWindow2 interface of each frame. You can then use the
IHTMLWindow2::document property to get the IHTMLDocument2 interface.
For example:
#include <mshtml.h>
#include <utilcls.h>
if( CppWebBrowser1->Document )
{
TComInterface<IHTMLDocument2> Doc;
CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&Doc);
if( Doc )
{
TComInterface<IHTMLFramesCollection2> Frames;
Doc->get_frames(&Frames);
if( Frames )
{
TVariant IndexOrName = WideString("frame name");
// or:
// TVariant IndexOrName = SomeIndex;
TVariant Frame;
Frames->item(&IndexOrName, &Frame);
if( (V_VT(&Frame) == VT_DISPATCH) &&
(V_DISPATCH(&Frame) != NULL) )
{
TComInterface<IHTMLWindow2> Window;
V_DISPATCH(&Frame)->QueryInterface(IID_IHTMLWindow2,
(LPVOID*)&Window);
if( Window )
{
TComInterface<IHTMLDocument2> FrameDoc;
Window->get_document(&FrameDoc);
if( FrameDoc )
{
// use FrameDoc as needed ...
}
}
}
}
}
}
Refer to the following documentation for more information:
Interfaces and Scripting Objects
http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/interface.asp
Gambit |
|
| Back to top |
|
 |
mike Guest
|
Posted: Sat Jan 06, 2007 4:48 am Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
Thank you Remy for responding to my question and problem.
I will study the code over the weekend and see if I can get this to work
properly.
Mike
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:459ec5bf$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"mike" <mfbrowne (AT) earthlink (DOT) nnet> wrote in message
news:459ebec4$1 (AT) newsgroups (DOT) borland.com...
I would like to programmably be able to click a button on a web
page loaded into a TCppWebBrowser.
You need to use the DOM intefaces for that. If the button has a name,
then you can use the IHTMLDocument2::all collection to find it
quickly. Otherwise, you have to drill down the parent/child hierarchy
manually. Either way, once you locate the button, you can obtain its
IHTMLElement interface and then call its click() method.
The web page has a Tree View, I believe, on the left side and the
button is located within this view.
There is no TreeView control in HTML.
If I view the source from within the browser the source looks like
below:
The only non-form button I see in that code is named "secure_exit". I
am assuming that the one you want. The code to access it would look
like this:
#include <mshtml.h
#include <utilcls.h
if( CppWebBrowser1->Document )
{
TComInterface<IHTMLDocument2> Doc;
CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&Doc);
if( Doc )
{
TComInterface<IHTMLElementCollection> All;
Doc->get_all(&All);
if( All )
{
TComInterface<IDispatch> Disp;
All->item(TVariant(WideString("secure_exit")),
TVariant(0), &Disp);
if( Disp )
{
TComInterface<IHTMLElement> Element;
Disp->QueryInterface(IID_IHTMLElement,
(LPVOID*)&Element);
if( Element )
Element->click();
}
}
}
}
This portion of the web page may also reside within a frame
That makes a big difference. You need the IHTMLDocument2 interface
for the specific frame that you are going to search. Starting with
the top-level Document, you can use its frames collection to access
the IHTMLWindow2 interface of each frame. You can then use the
IHTMLWindow2::document property to get the IHTMLDocument2 interface.
For example:
#include <mshtml.h
#include <utilcls.h
if( CppWebBrowser1->Document )
{
TComInterface<IHTMLDocument2> Doc;
CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&Doc);
if( Doc )
{
TComInterface<IHTMLFramesCollection2> Frames;
Doc->get_frames(&Frames);
if( Frames )
{
TVariant IndexOrName = WideString("frame name");
// or:
// TVariant IndexOrName = SomeIndex;
TVariant Frame;
Frames->item(&IndexOrName, &Frame);
if( (V_VT(&Frame) == VT_DISPATCH) &&
(V_DISPATCH(&Frame) != NULL) )
{
TComInterface<IHTMLWindow2> Window;
V_DISPATCH(&Frame)->QueryInterface(IID_IHTMLWindow2,
(LPVOID*)&Window);
if( Window )
{
TComInterface<IHTMLDocument2> FrameDoc;
Window->get_document(&FrameDoc);
if( FrameDoc )
{
// use FrameDoc as needed ...
}
}
}
}
}
}
Refer to the following documentation for more information:
Interfaces and Scripting Objects
http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/interface.asp
Gambit
|
|
|
| Back to top |
|
 |
mike Guest
|
Posted: Sat Jan 06, 2007 9:12 pm Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
Remy,
Again thank you for responding to me on this problem.
I tried the code you supplied and have the following results:
For the first code sample you supplied, the button was not found. Now
because I suspected there might be frames, and did find 2 frames located on
the web page. So I tried the second code sample and added the
TComInterface<IHTMLElementCollection> All;
for the framedoc reteived. However the button again was not found. I tried
this on both frame 0 and frame 1.
I then decided to get the source of the frames and save them to a file where
I could see what was actually within the framedoc. Upon this review I did
not see the button source in either frame doc. If I do a view source over
the area that does contain the button I do see it in notepad.
So I am totally confused on where this button definition could be within the
web page, and I am not sure how to find this information out.
I have reviewed the documentation you pointed me to but I am not sure what I
am looking for to help me out.
I can supply you with the web page navigation to see the web page yourself
if this will help out.
So I am at a loss and I am hoping you can point me in the right direction to
help me.
Thanks
Mike |
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Sun Jan 07, 2007 4:22 am Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
mike wrote:
| Quote: | For the first code sample you supplied, the button was not found.
|
How did you check that? The provided code is ok. You could add a
Showmessage to indicate that it found the button:
if( Element )
{
Element->click();
ShowMessage ( "Element->click();");
}
| Quote: | Now
because I suspected there might be frames,
|
There are no frames in the page you posted.
At first I thought that there were two buttons in that page. Well
there are but the second one is commented out. Please clean up
a page before you post it.
So it is about this button:
<p><input TYPE="button" NAME="secure_exit" VALUE=" Finished "
onClick="logout();">
The button is found and clicked with the provided code. Didn't
you see anyting happen? I did not either but that is because
the nesasary javasript function logout() failed.
Then i made the following function:
<script language=javascript>
function logout()
{
var url = "http://www.borland.com";
var widgeds = 'toolbar=0,status=0,width=200,height=150';
window.open(url,"",widgeds);
}
</script>
Now all functioned.
| Quote: | I can supply you with the web page navigation to see the web page yourself
if this will help out.
|
Why did not you post the exacturl with your first post?
Hans. |
|
| Back to top |
|
 |
mike Guest
|
Posted: Sun Jan 07, 2007 5:04 am Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
Hans,
Thank you for responding, I appreciate it.
Please see below for my answers on your questions.
"Hans Galema" <notused (AT) notused (DOT) nl> wrote in message
news:45a02189$1 (AT) newsgroups (DOT) borland.com...
| Quote: | mike wrote:
For the first code sample you supplied, the button was not found.
How did you check that? The provided code is ok. You could add a
Showmessage to indicate that it found the button:
if( Element )
{
Element->click();
ShowMessage ( "Element->click();");
}
|
I did two things to verify the button was not found. The first thing is I
traced the test application. The code to descover the element and click it
was never executed. I also did put a show message in and ran the application
and it again did not find the button.
| Quote: | Now because I suspected there might be frames,
There are no frames in the page you posted.
The actual page I posted was from a show source of the actual page during an |
internet session on the page. If I do a show source on different parts of
the internet window shown then I see different sources for the page. I did
not post all the pages as I would have made the original post rather long.
In my test application I have inserted a test for frames and it does that
there are 2 frames.
| Quote: | At first I thought that there were two buttons in that page. Well
there are but the second one is commented out. Please clean up
a page before you post it.
|
Well as I did not write this web page and it is from a server on the net I
wanted to show the page as I was seeing it from my test application. This is
why I did not clean it up.
| Quote: | So it is about this button:
|
Yes
| Quote: |
p><input TYPE="button" NAME="secure_exit" VALUE=" Finished "
onClick="logout();"
The button is found and clicked with the provided code. Didn't
you see anyting happen? I did not either but that is because
the nesasary javasript function logout() failed.
|
Ther function logout() should be executed from the source server. I have no
control over that.
| Quote: |
Then i made the following function:
script language=javascript
function logout()
{
var url = "http://www.borland.com";
var widgeds = 'toolbar=0,status=0,width=200,height=150';
window.open(url,"",widgeds);
}
/script
Now all functioned.
I can supply you with the web page navigation to see the web page
yourself
if this will help out.
Why did not you post the exacturl with your first post?
|
Well I suppose I should have posted it in the first post. I am posting it
now.
http://rpa.tblc.org/rpa/webauth.exe?lb=PALM
Borrower Id = 25913000705454
It will be the next page the button I am trying to access will be on. When I
try and find this button through my test application I never see it.
I hope you can assist me in this as I really do not understand why I cannot
get to this button.
Thanks very much.
Mike |
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Sun Jan 07, 2007 3:50 pm Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
mike wrote:
| Quote: | http://rpa.tblc.org/rpa/webauth.exe?lb=PALM
|
That is indeed a frameset after login.
/rpa/default/thetop.htm is the topframe and
/rpa/default/newauthlink.htm the bottomframe.
From that bottomframe the leftframe is
http://rpa.tblc.org/rpa/default/newlinks.htm
and you posted the complete code of that page.
You could have provided that info to begin with!
If you navigate directly to that page then the list
of authorized links is empty. But the Finished button
is there and Remy's code works. After using it a trouble-
shooting page displays.
Now what is the problem?
As you see: I did not try the code looping through all the
frames yet but if that is what you need I could do that too.
Hans. |
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Sun Jan 07, 2007 4:02 pm Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
mike wrote:
| Quote: | Ther function logout() should be executed from the source server. I have no
control over that.
|
Javascript is interpreted on the clientside. In your browser.
The logout() function is found in:
http://rpa.tblc.org/rpa/default/newAuthlib.js
which is included in the page we are speaking about.
Hans. |
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Sun Jan 07, 2007 4:04 pm Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
Hans Galema wrote:
| Quote: | http://rpa.tblc.org/rpa/webauth.exe?lb=PALM
That is indeed a frameset after login.
/rpa/default/thetop.htm is the topframe and
/rpa/default/newauthlink.htm the bottomframe.
From that bottomframe the leftframe is
http://rpa.tblc.org/rpa/default/newlinks.htm
|
So there are two framesets. I think that the code that Remy
posted only takes one frameset in account. You have to
make that code recursive so that it finds the second frameset too.
Hans. |
|
| Back to top |
|
 |
mike Guest
|
Posted: Sun Jan 07, 2007 8:07 pm Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
Hans,
Thank you very much for having a look at this for me, and now I will try and
understand what you have said to me.
I did modify Remy's code sample to take into account the 2 frames that I
found, but when I did I still did not find the button within either frameset
I located. So I must be doing something incorrect. I will relook at the code
sample and see if I can determine what I may be doing wrong and then post it
here for help.
Again thanks so much for assisting me.
Mike
"Hans Galema" <notused (AT) notused (DOT) nl> wrote in message
news:45a0c58e$1 (AT) newsgroups (DOT) borland.com...
| Quote: | mike wrote:
Ther function logout() should be executed from the source server. I have
no control over that.
Javascript is interpreted on the clientside. In your browser.
The logout() function is found in:
http://rpa.tblc.org/rpa/default/newAuthlib.js
which is included in the page we are speaking about.
Hans. |
|
|
| Back to top |
|
 |
mike Guest
|
Posted: Sun Jan 07, 2007 8:40 pm Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
Hans,
Well I am clearly not understanding why the button is not found. I am using
the following code and I thought the button would have been found as I am
taking into account the 2 frames, I think.
Can you point out what I am not understanding or where I have gone wrong.
Thanks very much
Mike
if( CppWebBrowser1->Document )
{
TComInterface<IHTMLDocument2> Doc;
CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&Doc);
if( Doc )
{
TComInterface<IHTMLFramesCollection2> Frames;
Doc->get_frames(&Frames);
if( Frames )
{
long cnt = 0;
Frames->get_length(&cnt);
for(long l = 0; l < cnt; ++l)
{
// TVariant IndexOrName = WideString("frame name");
// or:
TVariant IndexOrName = l;
TVariant Frame;
Frames->item(&IndexOrName, &Frame);
if( (V_VT(&Frame) == VT_DISPATCH) && (V_DISPATCH(&Frame)
!= NULL) )
{
TComInterface<IHTMLWindow2> Window;
V_DISPATCH(&Frame)->QueryInterface(IID_IHTMLWindow2,(LPVOID*)&Window);
if( Window )
{
TComInterface<IHTMLDocument2> FrameDoc;
Window->get_document(&FrameDoc);
if( FrameDoc )
{
// use FrameDoc as needed ...
TComInterface<IHTMLElementCollection> All;
FrameDoc->get_all(&All);
if( All )
{
TComInterface<IDispatch> Disp;
All->item(TVariant(WideString("secure_exit")),TVariant(0),
&Disp);
if( Disp )
{
TComInterface<IHTMLElement> Element;
Disp->QueryInterface(IID_IHTMLElement,(LPVOID*)&Element);
if( Element )
{
ShowMessage (
"Element->click();");
Element->click();
break ;
}
}
}
}
}
}
}
}
}
} |
|
| Back to top |
|
 |
Michael Harris Guest
|
Posted: Sun Jan 07, 2007 10:22 pm Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
if you add the 'get_source' method mentioned earlier, you will see why the
code failes.
if( FrameDoc )
{
ShowMessage(Get_Source(FrameDoc));
// use FrameDoc as needed ...
--
Michael
"mike"wrote in message
| Quote: | Hans,
Well I am clearly not understanding why the button is not found. I am
using the following code and I thought the button would have been found as
I am taking into account the 2 frames, I think.
Can you point out what I am not understanding or where I have gone wrong.
|
|
|
| Back to top |
|
 |
mike Guest
|
Posted: Sun Jan 07, 2007 11:29 pm Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
Michael
Thank you for responding, however I get an undefined function when inserting
this.
Where is the function defined or how to get the actual source of the frame.
Thanks
Mike
"Michael Harris" <techonos-NO-SPAM-@attbi.com> wrote in message
news:45a11e90$1 (AT) newsgroups (DOT) borland.com...
| Quote: | if you add the 'get_source' method mentioned earlier, you will see why the
code failes.
if( FrameDoc )
{
ShowMessage(Get_Source(FrameDoc));
// use FrameDoc as needed ...
--
Michael
"mike"wrote in message
Hans,
Well I am clearly not understanding why the button is not found. I am
using the following code and I thought the button would have been found
as I am taking into account the 2 frames, I think.
Can you point out what I am not understanding or where I have gone wrong.
|
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Sun Jan 07, 2007 11:43 pm Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
mike wrote:
Until now I did not try your code but looking at it the following
comes to mind:
| Quote: | long cnt = 0;
Frames->get_length(&cnt);
|
What is the value of count?
ShowMessage ( "cnt: " + IntToStr ( (int)cnt ) );
| Quote: | for(long l = 0; l < cnt; ++l)
{
TVariant IndexOrName = l;
|
Is that character L ? or digit 1 ?
Please do never use variablenames with only one character. Especially
do never use an l. It looks to much a 1.
Hans. |
|
| Back to top |
|
 |
mike Guest
|
Posted: Mon Jan 08, 2007 12:04 am Post subject: Re: Help with TCppWebBrowser - Find and click a button |
|
|
Hans,
Sorry for the one character variable name. It is L not a digit 1.
The reported count for the number of frames is 2.
Thanks for continuing to assist me in this.
Mike
"Hans Galema" <notused (AT) notused (DOT) nl> wrote in message
news:45a131a1$1 (AT) newsgroups (DOT) borland.com...
| Quote: | mike wrote:
Until now I did not try your code but looking at it the following
comes to mind:
long cnt = 0;
Frames->get_length(&cnt);
What is the value of count?
ShowMessage ( "cnt: " + IntToStr ( (int)cnt ) );
for(long l = 0; l < cnt; ++l)
{
TVariant IndexOrName = l;
Is that character L ? or digit 1 ?
Please do never use variablenames with only one character. Especially
do never use an l. It looks to much a 1.
Hans. |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|