Solved

Twebbrowser Elements at runtime ?

Posted on 2008-10-05
11
333 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

23 Experts available now in Live!

Get 1:1 Help Now