Solved

WebBrowser Insert text into input type box

Posted on 2004-04-25
3
1,260 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

11 Experts available now in Live!

Get 1:1 Help Now