Solved

Twebbrowser Elements at runtime ? - Part II

Posted on 2008-10-10
7
479 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 79
Using idhttp to login to instagram 2 89
Making delphi communicate with a c# service 16 102
Adoquery sql  left join does not work 25 89
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now