Solved

WebBrowser Insert text into input type box

Posted on 2004-04-25
3
1,285 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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
Delphi selector screen 2 92
Run video youtube webbrowse 10 73
tidtcpserver connection lost handle 2 110
Adoquery sql  left join does not work 25 104
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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