• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 514
  • Last Modified:

Twebbrowser Elements at runtime ? - Part II

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
geocoins-software
Asked:
geocoins-software
  • 4
  • 3
1 Solution
 
wd123Commented:
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
 
geocoins-softwareAuthor Commented:
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
 
wd123Commented:
show me you webpage.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
geocoins-softwareAuthor Commented:
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
 
geocoins-softwareAuthor Commented:
wd123, please post your solution so i can award the points - thanks!
0
 
wd123Commented:
i don't save it ;) can you just  award ?
0
 
geocoins-softwareAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now