Solved

Twebbrowser Elements at runtime ? - Part II

Posted on 2008-10-10
7
471 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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