Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Twebbrowser Elements at runtime ?

Posted on 2008-10-05
11
Medium Priority
?
349 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
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

730 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