Solved

Twebbrowser Elements at runtime ? - Part II

Posted on 2008-10-10
7
487 Views
Last Modified: 2010-05-18
I am trying to Control the elements of a webpage in my TWebBrowser component.

I have two TWebBrowsers displayed on my form. (WebBrowser1 & WebBrowser2)

I navigate to a webpage in WebBrowser1 - which is nothing but a list of links.

I would like to step through each of these links and load another page into WebBrowser2 for each of the links. Find a specific link in each of those pages and click it. Which in turn would load another page (in Webbrowser2). In this page I would like to select an item from a dropdown and click the submit button.

See the code below:

It kinds works, but it never makes it to the last page to fill in the control and submit the button

Thanks
procedure TfrmMain.BtnOKClick(Sender: TObject);
var
 Links1, Links2, Elements1: OleVariant;
 i, j, K: integer;
begin
 Links1:=WebBrowser1.OleObject.Document.links;
 for i:=0 to Links1.Length-1 do
 begin
  Links1.item(i).Click;
  while WebBrowser2.ReadyState<>4 do
  begin
   sleep(50);
   Application.ProcessMessages;
  end;
  Links2:=WebBrowser2.OleObject.Document.links;
  for J:= 0 to Links2.Length-1 do
  begin
   if Links2.item(j).id = 'ctl00_ContentBody_LogLink' then
  begin
   Links2.item(j).click;
   while WebBrowser2.ReadyState<>4 do
   begin
    sleep(50);
    Application.ProcessMessages;
   end;
   Elements1:=WebBrowser2.OleObject.Document.forms.item(0).elements;
   for k:= 0 to Elements1.Length-1 do
   begin
    if (el3.item(k).type = 'select-one') AND (el3.item(k).id = 'LogBookPanel1_ddLogType') then
    begin
     el3.item(k).value:= '48';
    end
    else
    if  (el3.item(k).type = 'submit') AND  (el3.item(k).id = 'LogBookPanel1_LogButton') then
    begin
     el3.item(k).click;
    end;
   end;
   while WebBrowser2.ReadyState<>4 do
   begin
    sleep(500);
    Application.ProcessMessages;
   end;
  end;
  end;
 end;
end;

Open in new window

0
Comment
Question by:geocoins-software
  • 4
  • 3
7 Comments
 
LVL 5

Expert Comment

by:wd123
ID: 22693484
you check if (id=LogBookPanel1_ddLogType) else submit;
this "else" don't need here.
   for k:= 0 to Elements1.Length-1 do   begin
    if (el3.item(k).type = 'select-one') AND (el3.item(k).id = 'LogBookPanel1_ddLogType') then el3.item(k).value:= '48';
    if  (el3.item(k).type = 'submit') AND  (el3.item(k).id = 'LogBookPanel1_LogButton') then el3.item(k).click;
    end;

Open in new window

0
 

Author Comment

by:geocoins-software
ID: 22711458
Sorry, I was gone away on a trip for the last 3 days.

wd123:

Although your solution did fix an issue, it would not have been noticed until later in the execution. It does not solve the posted issue.  My code never makes it to the page where you solution would come into play.

thanks
0
 
LVL 5

Expert Comment

by:wd123
ID: 22711518
show me you webpage.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:geocoins-software
ID: 22711955
send me an email at info AT geocoins-software DOT com

and I will reply to it with the link and more info and pictures.

Sorry, I know its against policy to take this offline, however, its only for the matter to show the webpages.

thanks
0
 

Author Comment

by:geocoins-software
ID: 22733273
wd123, please post your solution so i can award the points - thanks!
0
 
LVL 5

Accepted Solution

by:
wd123 earned 500 total points
ID: 22735980
i don't save it ;) can you just  award ?
0
 

Author Comment

by:geocoins-software
ID: 22736071
I have attached it to this comment
var
  Form1: TForm1; load:boolean;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
var el:OleVariant;
code:string;
begin
code:='AZ74NC';
//firts of all login ...
WebBrowser1.Navigate('http://www.geocaching.com/login/default.aspx');
while WebBrowser1.ReadyState<>4 do begin sleep(50);Application.ProcessMessages;end;
WebBrowser1.OleObject.Document.getelementbyid('myUsername').value:='geo_lobo_2008';
WebBrowser1.OleObject.Document.getelementbyid('myPassword').value:='ilovecaching';
WebBrowser1.OleObject.Document.getelementbyid('cookie').checked:=true;
load:=true;
WebBrowser1.OleObject.Document.getelementbyid('Button1').click;
while load do begin sleep(50);Application.ProcessMessages;end;
//now loading
WebBrowser1.Navigate('http://www.geocaching.com/track/details.aspx?tracker='+code);
while WebBrowser1.ReadyState<>4 do begin sleep(50);Application.ProcessMessages;end;
load:=true;
WebBrowser1.OleObject.Document.getelementbyid('ctl00_ContentBody_LogLink').click;
while load do begin sleep(50);Application.ProcessMessages;end;
//now filling comment
WebBrowser1.OleObject.Document.getelementbyid('LogBookPanel1_ddLogType').value:='48';
WebBrowser1.OleObject.Document.getelementbyid('LogBookPanel1_DateTimeLogged_Month').value:=MonthOf(Now);
WebBrowser1.OleObject.Document.getelementbyid('LogBookPanel1_DateTimeLogged_Day').value:=DayOf(Now);
WebBrowser1.OleObject.Document.getelementbyid('LogBookPanel1_DateTimeLogged_Year').value:=YearOf(Now);;
WebBrowser1.OleObject.Document.getelementbyid('LogBookPanel1_tbCode').value:=code;
WebBrowser1.OleObject.Document.getelementbyid('LogBookPanel1_tbLogInfo').value:='Thanks for allowing me to discover!';
load:=true;
WebBrowser1.OleObject.Document.getelementbyid('LogBookPanel1_LogButton').click;
while load do begin sleep(50);Application.ProcessMessages;end;
//submint done.
end;
 
 
procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
load:=false;
end;

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange behavior when a form is closed 6 69
Magic Software info 18 144
Problem working with dynamic array - help 2 36
Delphi Firemonkey : user drawing in window 3 28
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

726 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