Solved

WebBrowser Insert text into input type box

Posted on 2004-04-25
3
1,281 Views
Last Modified: 2008-01-09
Hi;


I have written a program in Delphi 7 which views a website in WebBrowser1.

There is a box on the page for user and password.I have tried numurous ways
to insert the required text into each box but have not been successful.

Here is the some source from the webpage.

<td><input type=text class=input_m size=25 name="username" value=></td>

Can I  use WebBroswer1.Document ?

Is so how ?
Or is there another way ?


Thanks
Bruce
0
Comment
Question by:delphimate
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 500 total points
ID: 10916046
Hi,

From 'Project-Import Type Library' select 'Microsoft HTML Object Library' and press 'Create Unit' button. This will add MSHTML_TLB to your project. Then use the function below:

uses MSHTML_TLB, ComObj;

procedure KeyInputBox(Browser:TWebBrowser; ElementName, Value: string);
var
  WebDoc : IHTMLDocument2;
  pDispatch : IDISPATCH;
  elements : IHTMLElementCollection;
  Input: IHTMLInputElement;
begin
    OleCheck(Browser.Document.QueryInterface(IID_IHTMLDocument2, WebDoc));
    // grab all elements:
    elements := WebDoc.Get_all;
    // find first with the name ElementName:
    pDispatch := elements.item(ElementName, 0);
    // get it:
    OleCheck(pDispatch.QueryInterface(IID_IHTMLInputElement, Input));
    // and set its value:
    Input.value := Value;
end;

// usage:
procedure TForm1.Button2Click(Sender: TObject);
begin
  KeyInputBox(WebBrowser1, 'username', 'YourUserName');
end;

Regards, Geo
0
 

Author Comment

by:delphimate
ID: 10918178
Thanks Geo,

I eventually got it to work !!

What happened when I did this 'Microsoft HTML Object Library' and press 'Create Unit' button,
Delphi hung up and I had to ctrl-alt-del in win2000 to end task which closed the program.
When I got back in I noticed it created a .pas in the Lib,and it worked.When I entered
KetInputBox for the first time it took 3 minutes before I could keep typing.It just sat there
with the hour glass.But after all this the program works fine.

Also they have a submit button I wish to activate after entering my username and password.

>< input type=image name=submit src="http.....".

any ideas ?

thanks
Bruce
0
 
LVL 17

Expert Comment

by:geobul
ID: 10918381
You are welcome :-)

If the button was defined like:
<INPUT TYPE=submit NAME="OKBtn" ...
I would give you some source. But I can't for your case, sorry.

Regards, Geo
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 101
Tembedded WB animatid gifs not animated on some pcs 2 83
JAudiorecorder record freezing the app 29 74
scroll down TListBox component in Delphi 1 19
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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