Solved

Twebbrowser Elements at runtime ?

Posted on 2008-10-05
11
330 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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 500 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

20 Experts available now in Live!

Get 1:1 Help Now