Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1336
  • Last Modified:

WebBrowser Insert text into input type box

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
delphimate
Asked:
delphimate
  • 2
1 Solution
 
geobulCommented:
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
 
delphimateAuthor Commented:
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
 
geobulCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now