Solved

Twebbrowser Elements at runtime ?

Posted on 2008-10-05
11
342 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
[X]
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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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