Solved

WebBrowser Insert text into input type box

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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