wildzero
asked on
Webbrowser - Getting form elements in frames
Gidday there,
If I load a page and use
showmessage(IntToStr(WebBr owser.OleO bject.Docu ment.Forms .Length))
I get the number of forms on the page.
ie 1 or 2 ect
Now if that page has frames it always returns 0
How can I get the count of forms, or more importantly, how can I access a forms elements on a page with frames?
Like
WebBrowser.OleObject.docum ent.forms. item(1).el ements.ite m('myname' ).value:= 'Bob';
Cheers guys
If I load a page and use
showmessage(IntToStr(WebBr
I get the number of forms on the page.
ie 1 or 2 ect
Now if that page has frames it always returns 0
How can I get the count of forms, or more importantly, how can I access a forms elements on a page with frames?
Like
WebBrowser.OleObject.docum
Cheers guys
If you had a link that I could help test on that would be helpful.
But anyway, take a look at this code.
And see if you can accomplish what you need with it.
How t0 interate through Frames
========================== ========== =
procedure TForm1.Button1Click(Sender : TObject);
var
i: integer;
begin
for i := 0 to (WebBrowser1.OleObject.Doc ument.fram es.Length - 1) do
if WebBrowser1.OleObject.Docu ment.frame s.item(i). document.q ueryComman dEnabled(' Copy') then
ShowMessage('copy command is enabled for frame no.' + IntToStr(i));
end;
========================== ========== ==
Carrzkiss
But anyway, take a look at this code.
And see if you can accomplish what you need with it.
How t0 interate through Frames
==========================
procedure TForm1.Button1Click(Sender
var
i: integer;
begin
for i := 0 to (WebBrowser1.OleObject.Doc
if WebBrowser1.OleObject.Docu
ShowMessage('copy command is enabled for frame no.' + IntToStr(i));
end;
==========================
Carrzkiss
ASKER
Carrzkiss,
Gidday there
Let me throw up a site - while I do that
If thats how to interate though frames, how could I use that to fill out a form on a frame?
like, interate though frames to interate though forms ;)
Gidday there
Let me throw up a site - while I do that
If thats how to interate though frames, how could I use that to fill out a form on a frame?
like, interate though frames to interate though forms ;)
Put up a site, and send the link over, I will take a look at it.
Also, if you have some sample code that you are using to do it.
Without Frames, Then please post that as well.
This way we are both working on the same track.
Carrzkiss
Also, if you have some sample code that you are using to do it.
Without Frames, Then please post that as well.
This way we are both working on the same track.
Carrzkiss
Code for filling in the forms, it what I meant to say
ASKER
http://storeit-online.com/framestest/index.html
There is a url there of something I am trying to do, just like fillin the fields of say, the main page (name and url)
I tried using this
For i := 0 to WebBrowser.OleObject.Docum ent.Forms. Length-1 do
begin
WebBrowser.OleObject.docum ent.forms. item(i).el ements.ite m('name'). value:= 'Bob';
WebBrowser.OleObject.docum ent.forms. item(i).el ements.ite m(url).val ue:= 'http://mysite.com';
end;
Even just showmessage(IntToStr(WebBr owser.OleO bject.Docu ment.Forms .Length));
which normally returns more then 0
There is a url there of something I am trying to do, just like fillin the fields of say, the main page (name and url)
I tried using this
For i := 0 to WebBrowser.OleObject.Docum
begin
WebBrowser.OleObject.docum
WebBrowser.OleObject.docum
end;
Even just showmessage(IntToStr(WebBr
which normally returns more then 0
ASKER
Hey there, manage to get any further?
ASKER
Figured it out! Finally
procedure TForm1.Button5Click(Sender : TObject);
var
g, f, k : integer;
pDispatch : IDISPATCH;
textarea: IHTMLTextAreaElement;
begin
for f := 0 to WebBrowser1.OleObject.Docu ment.frame s.Length - 1 do
begin
showmessage(intToStr(WebBr owser1.Ole Object.Doc ument.fram es.item(f) .document. Forms.Leng th));
for g := 0 to WebBrowser1.OleObject.Docu ment.frame s.item(f). document.F orms.Lengt h-1 do
begin
for k := 0 to WebBrowser1.OleObject.Docu ment.frame s.item(f). document.f orms.item( g).element s.length-1 do
begin
showmessage(WebBrowser1.Ol eObject.Do cument.fra mes.item(f ).document .forms.ite m(g).eleme nts.item(k ).name);
showmessage(WebBrowser1.Ol eObject.Do cument.fra mes.item(f ).document .forms.ite m(g).eleme nts.item(k ).tagname) ;
showmessage(WebBrowser1.Ol eObject.Do cument.fra mes.item(f ).document .forms.ite m(g).eleme nts.item(k ).type);
{Fill text field}
WebBrowser1.OleObject.Docu ment.frame s.item(f). document.f orms.item( g).element s.item('na me').value := 'Bob';
{Fill in a text area}
pDispatch := WebBrowser1.OleObject.Docu ment.frame s.item(2). document.f orms.item( 0).element s.item('S1 ', 0);
try
OleCheck(pDispatch.QueryIn terface(II D_IHTMLTex tAreaEleme nt, textarea));
textarea.Set_value('Hello' );
except
end;
end;
end;
end;
end;
procedure TForm1.Button5Click(Sender
var
g, f, k : integer;
pDispatch : IDISPATCH;
textarea: IHTMLTextAreaElement;
begin
for f := 0 to WebBrowser1.OleObject.Docu
begin
showmessage(intToStr(WebBr
for g := 0 to WebBrowser1.OleObject.Docu
begin
for k := 0 to WebBrowser1.OleObject.Docu
begin
showmessage(WebBrowser1.Ol
showmessage(WebBrowser1.Ol
showmessage(WebBrowser1.Ol
{Fill text field}
WebBrowser1.OleObject.Docu
{Fill in a text area}
pDispatch := WebBrowser1.OleObject.Docu
try
OleCheck(pDispatch.QueryIn
textarea.Set_value('Hello'
except
end;
end;
end;
end;
end;
Hello WildZero;
I am so sorry that I have not gotten back with you.
It has been rather hectic here at my house over the weekend.
And I just took a break from doing anything on the computer.
(The life of being a single parent)
I am glad to see that you was able to figure it out with the
Code that I sent over.
Maybe I am just wore out, But I cannot get it to compile.
Getting a few errors. ( Maybe rest will help my brain ;-) )
[Error] Unit1.pas(34): Undeclared identifier: 'IHTMLTextAreaElement'
[Error] Unit1.pas(51): Undeclared identifier: 'OleCheck'
[Error] Unit1.pas(51): Undeclared identifier: 'IID_IHTMLTextAreaElement'
&
[Error] Unit1.pas(52): Missing operator or semicolon
On this: textarea.Set_value('Hello' );
Anyway.
Hope that you make something that makes you a lot of fortune.
Take Care
Carrzkiss
I am so sorry that I have not gotten back with you.
It has been rather hectic here at my house over the weekend.
And I just took a break from doing anything on the computer.
(The life of being a single parent)
I am glad to see that you was able to figure it out with the
Code that I sent over.
Maybe I am just wore out, But I cannot get it to compile.
Getting a few errors. ( Maybe rest will help my brain ;-) )
[Error] Unit1.pas(34): Undeclared identifier: 'IHTMLTextAreaElement'
[Error] Unit1.pas(51): Undeclared identifier: 'OleCheck'
[Error] Unit1.pas(51): Undeclared identifier: 'IID_IHTMLTextAreaElement'
&
[Error] Unit1.pas(52): Missing operator or semicolon
On this: textarea.Set_value('Hello'
Anyway.
Hope that you make something that makes you a lot of fortune.
Take Care
Carrzkiss
Your errros come from missing units in your uses.
Be aware that you WILL NOT be able to do this on frames that are not on your the same domain as
the frameset. obtaining info from cross-domain frames will be caught by IE's security measures.
Be aware that you WILL NOT be able to do this on frames that are not on your the same domain as
the frameset. obtaining info from cross-domain frames will be caught by IE's security measures.
ASKER
MSHTML_TLB (MSHTML for some) and SHDocVw I think it is you need.
Eddie, you are right - and thats the thing I need to work nothing you can think of/suggest?
Eddie, you are right - and thats the thing I need to work nothing you can think of/suggest?
Uses MSHTML_TLB, SHDocVw, ComObj;
Thanks, good now I can test it out.
Thanks, good now I can test it out.
I can't get that code to work at all.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
"WebBrowser1.OleObject.Doc ument.fram es.item(0) .Document. forms.Item (0).Item(0 ).Value:=' Bob';" will set the value of the first item on the first form of the first frame to 'Bob' provided that such an item, form and frame exist, and provided that the item can be set.
Hope that helps you.
A.
"WebBrowser1.OleObject.Doc
Hope that helps you.
A.
You might also want to look at http://www.cryer.co.uk/brian/delphi/twebbrowser/twebbrowser_oleobject.htm.
A.
A.
Aqueath,
It doesn't work on ;ater versions of IE6 because of cross-domain security.
I can't even get it to work when the frame is on my own domain.
It doesn't work on ;ater versions of IE6 because of cross-domain security.
I can't even get it to work when the frame is on my own domain.
Eddie,
According to Windows Update I have upgraded to the latest version of IE6, and this still works on my machine. I did however use the TWebBrowser component while testing this. Can you list the page you tried this on? And you IE6 version?
A.
According to Windows Update I have upgraded to the latest version of IE6, and this still works on my machine. I did however use the TWebBrowser component while testing this. Can you list the page you tried this on? And you IE6 version?
A.
ASKER
A.
I got the code I posted to work fine but doesn't with cross domain things.
ie one frame on a different domain name.
Did you try that?
I am running IE6 on both machines
I got the code I posted to work fine but doesn't with cross domain things.
ie one frame on a different domain name.
Did you try that?
I am running IE6 on both machines
I tried it both ways and couldn't get it to work in either situation.
Here is the HTML I used:
<html>
<head>
<title>Untitled Document</title>
</head>
<frameset rows="14.3%,*,12.3%" frameborder="NO" border="1" framespacing="0">
<frame src="gallery_2.html" name="topFrame" scrolling="NO" noresize frameborder="no" border="0">
<frameset cols="27%,70%" frameborder="no" border="1" framespacing="0" marginwidth=0 marginheight=0>
<frame src="gallery_3.html" name="mainFrame" scrolling="NO" noresize>
<frame src="http://www.delphipages.com" name="dynamicframe" scrolling="yes" noresize frameborder="yes">
</frameset>
<frame src="gallery_4.html" name="topFrames" scrolling="NO" noresize frameborder="no">
</frameset>
</html>
The gallery_X.html pages are pages on my site.
If I change the delphipages.com url to another page on my site, it still doesn't work.
Of course I'm also trying this locally, too, (http://locahost/framsettest.html) and it doesn't work in either case.
Here is the HTML I used:
<html>
<head>
<title>Untitled Document</title>
</head>
<frameset rows="14.3%,*,12.3%" frameborder="NO" border="1" framespacing="0">
<frame src="gallery_2.html" name="topFrame" scrolling="NO" noresize frameborder="no" border="0">
<frameset cols="27%,70%" frameborder="no" border="1" framespacing="0" marginwidth=0 marginheight=0>
<frame src="gallery_3.html" name="mainFrame" scrolling="NO" noresize>
<frame src="http://www.delphipages.com" name="dynamicframe" scrolling="yes" noresize frameborder="yes">
</frameset>
<frame src="gallery_4.html" name="topFrames" scrolling="NO" noresize frameborder="no">
</frameset>
</html>
The gallery_X.html pages are pages on my site.
If I change the delphipages.com url to another page on my site, it still doesn't work.
Of course I'm also trying this locally, too, (http://locahost/framsettest.html) and it doesn't work in either case.
ASKER
With
WebBrowser1.OleObject.Docu ment.frame s.item(0). Document.f orms.Item( 0).Item(0) .Value:='B ob';
I get Access Denied.
When I do this
showmessage(IntToStr(WebBr owser1.Ole Object.Doc ument.fram es.Length) );
for f := 0 to WebBrowser1.OleObject.Docu ment.frame s.Length - 1 do
showmessage(intToStr(WebBr owser1.Ole Object.Doc ument.fram es.item(f) .document. Forms.Leng th));
I get the first message (2 for two forms)
But then I get a access denied message as well.....
WebBrowser1.OleObject.Docu
I get Access Denied.
When I do this
showmessage(IntToStr(WebBr
for f := 0 to WebBrowser1.OleObject.Docu
showmessage(intToStr(WebBr
I get the first message (2 for two forms)
But then I get a access denied message as well.....
Wildzero,
Can you tell me the url of the page you're trying to reach?
A.
Can you tell me the url of the page you're trying to reach?
A.
ASKER
I just tried this and got the same result.
Open up notepad and paste this
<html>
<head>
<title>Untitled Document</title>
</head>
<frameset rows="595,*,115" frameborder="NO" border="1" framespacing="0">
<frame src="http://www.delphipages.com" name="dynamicframe" scrolling="yes" noresize frameborder="yes">
<frameset cols="51%,49%" frameborder="no" border="1" framespacing="0" marginwidth=0 marginheight=0>
<frame name="mainFrame" scrolling="NO" noresize>
<frame name="topFrame" scrolling="NO" noresize frameborder="no" border="0">
</frameset>
<frame name="topFrames" scrolling="NO" noresize frameborder="no">
</frameset>
</html>
Save as test.html to C:\
Then set webbrowser1 to navigate to C:\txt.html
Then try this
showmessage(IntToStr(WebBr owser1.Ole Object.Doc ument.fram es.Length) );
for f := 0 to WebBrowser1.OleObject.Docu ment.frame s.Length - 1 do
showmessage(intToStr(WebBr owser1.Ole Object.Doc ument.fram es.item(f) .document. Forms.Leng th));
It came up with 4 as expected, but then got access denied..
Open up notepad and paste this
<html>
<head>
<title>Untitled Document</title>
</head>
<frameset rows="595,*,115" frameborder="NO" border="1" framespacing="0">
<frame src="http://www.delphipages.com" name="dynamicframe" scrolling="yes" noresize frameborder="yes">
<frameset cols="51%,49%" frameborder="no" border="1" framespacing="0" marginwidth=0 marginheight=0>
<frame name="mainFrame" scrolling="NO" noresize>
<frame name="topFrame" scrolling="NO" noresize frameborder="no" border="0">
</frameset>
<frame name="topFrames" scrolling="NO" noresize frameborder="no">
</frameset>
</html>
Save as test.html to C:\
Then set webbrowser1 to navigate to C:\txt.html
Then try this
showmessage(IntToStr(WebBr
for f := 0 to WebBrowser1.OleObject.Docu
showmessage(intToStr(WebBr
It came up with 4 as expected, but then got access denied..
You can't just navigate to c:\txt.html. You must place it in inetpub\wwwroot and use http://locahost/txt.html.
I tried it that way and got the same result.
I tried it that way and got the same result.
ASKER
Eh?
I placed it on c:\ and naviagated to it just fine
Got the same result as if it was on the internet anyway
I placed it on c:\ and naviagated to it just fine
Got the same result as if it was on the internet anyway
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Aqueath - Thanks for the msg and summary, but it doesn't really get me any further ahead then my post "Figured it out! Finally....." I do appreaciate the time you've put into it though... Just gota figure out the cross domain thing...
I was working on a MHTML (web archive) processor and was having major problems with Frames
and IFrames. Then I ran accross a post on comp.infosystems.authoring .html about the cross-domain
security issue.
Now, I am not using IHTMLDocument2 anymore, I just use idHTTP and TRegEx to parse the HTML. When
I run across a frame/iframe, I download the source separately.
I am trying to recreate the technique used in this VB.Net article in Delphi:
http://www.codeproject.com/vb/net/MhtBuilder.asp#xx979211xx
and IFrames. Then I ran accross a post on comp.infosystems.authoring
security issue.
Now, I am not using IHTMLDocument2 anymore, I just use idHTTP and TRegEx to parse the HTML. When
I run across a frame/iframe, I download the source separately.
I am trying to recreate the technique used in this VB.Net article in Delphi:
http://www.codeproject.com/vb/net/MhtBuilder.asp#xx979211xx
ASKER
mmmm
thats what I may have to do
A friend pointed out that Robo form handles frames and iframes so there must be some way - maybe it has it's own build in html engine. Who knows. Tis a shame...
thats what I may have to do
A friend pointed out that Robo form handles frames and iframes so there must be some way - maybe it has it's own build in html engine. Who knows. Tis a shame...
So, is that what you are doing, building a tool to download entire websites either into a MHT file or a directory?
ASKER
Negative,
Trying to get the form elements from frames.
I may have to parse the html and if there are frames load them up somehow and go from there...
Herm...
Trying to get the form elements from frames.
I may have to parse the html and if there are frames load them up somehow and go from there...
Herm...
but WHY?
ASKER
So I can fill them out
ANy particular site you are working with or just in general?
ASKER
Just in general, I've got everything working but the cross-domain thing....
:)
:)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks everyone for there feedback...
ASKER
Crap was ment to hit A!
ASKER