Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Twebbrowser Elements at runtime ?

Posted on 2008-10-05
11
Medium Priority
?
356 Views
Last Modified: 2010-08-05
In code, how can i control a webpage's controls (elements) at runtime.

For example, if you look at the google page in a TWebBrowser.

http://www.google.com/

1.) At runtime (using code) how can i place text in the search box and click the search button?

2. a) At runtime (using code) how can i click the "About Google" link

2. b) At runtime (using code) how can determine that step 2.a was successful (wait for) before I do something else.

thanks
0
Comment
Question by:geocoins-software
11 Comments
 
LVL 8

Expert Comment

by:BdLm
ID: 22645928
ad 1: why to click the search button,
directly call the querry
   TWebbrowser.navigate('http://www.google.de/search?hl=de&q=test+query&btnG=Google-Suche&meta=')

test and query are the key words
0
 
LVL 8

Expert Comment

by:BdLm
ID: 22645934
ad 2 b:  
Called when a navigation operation has completed or been interrupted. Downloading should not be confused with rendering of the page (see also OnDocumentComplete).

procedure YourForm.WebBrowser_OnDownloadComplete(
  Sender: TObject);
see  --> Called when a navigation operation has completed or been interrupted. Downloading should not be confused with rendering of the page (see also OnDocumentComplete).

procedure YourForm.WebBrowser_OnDownloadComplete(
  Sender: TObject);
0
 

Author Comment

by:geocoins-software
ID: 22645936
well, because google was just an example.....it may not be known on the official page
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:geocoins-software
ID: 22645947
>ad 2 b:  
>Called when a navigation operation has completed or been interrupted. Downloading should not be >confused with rendering of the page (see also OnDocumentComplete).

>procedure YourForm.WebBrowser_OnDownloadComplete(
>  Sender: TObject);
>see  --> Called when a navigation operation has completed or been interrupted. Downloading should >not be confused with rendering of the page (see also OnDocumentComplete).

>procedure YourForm.WebBrowser_OnDownloadComplete(
>  Sender: TObject);

sorry, none of this makes any sense to me. I dont understand what you are trying to say
0
 
LVL 8

Expert Comment

by:BdLm
ID: 22645951
if it is very general approach:

go and get the HTML file, look for the buttons definition and get the methodes  post .....
what about that ?

0
 
LVL 8

Expert Comment

by:BdLm
ID: 22645959
are you using the TWebbRowser component for reading HTML files ?

if yes -> TWebbrowser has an event if a file is completly loaded. Please read the complete doku for TWebbrowser.
0
 
LVL 5

Accepted Solution

by:
wd123 earned 2000 total points
ID: 22645991
all in code:
var
  Form1: TForm1; loading:boolean;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
el:OleVariant;
begin
WebBrowser1.Navigate('http://www.google.com');
while WebBrowser1.ReadyState<>4 do Application.ProcessMessages; //wait while page loading
el:=WebBrowser1.OleObject.Document.forms.item(0).elements;
for i:=0 to el.Length-1 do begin
  if el.item(i).type='text' then el.item(i).value:='hellow world'; //place text
  if el.item(i).name='btnG' then begin loading:=true;el.item(i).click;break;end; //click on the button
end;
while loading do Application.ProcessMessages; //wait while page loading
showmessage('Search done !');
//------ click on link
WebBrowser1.Navigate('http://www.google.com');
while WebBrowser1.ReadyState<>4 do Application.ProcessMessages; //wait while page loading
el:=WebBrowser1.OleObject.Document.links;
for i:=0 to el.Length-1 do
 if pos('about.html',el.item(i).href)<>0 then el.item(i).click;
end;
 
procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
begin
loading:=false;
end;

Open in new window

0
 
LVL 8

Expert Comment

by:BdLm
ID: 22646044
there are to different approaches

a) know where you are and what you have to do :  
    call the search page directly withe the webbrowser.navigate function

b) get the HTML Code, look for the button coomand and try to understand and then navigate there
0
 
LVL 13

Expert Comment

by:ThievingSix
ID: 22646691
@wd123:

On line 13 it should be something like



While WebBrowser1.ReadyState<> 4 Do
  begin
  Sleep(50);
  Application.ProcessMessages;
end;

Open in new window

0
 

Author Closing Comment

by:geocoins-software
ID: 31503224
NICE!  Thanks!
0
 

Author Comment

by:geocoins-software
ID: 22662354
@wd123

See my question here:

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_23786385.html

Post a link to your answer answer and I will award you the posts to that one as well


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

879 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