Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Twebbrowser Elements at runtime ? - Part II

Posted on 2008-10-10
7
484 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

791 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