make delphi press a button in a website?

hi ,
is there anyway to make delphi press buttons on websites ?

example :
<input value="test" type="button" id="100" />

Open in new window


how can i make delphi press that button?
im using Tiehttp component

thx


evilkidAsked:
Who is Participating?
 
MorphorCommented:
There are two ways of "clicking the button".

The first way, using TWebBrowser and handles (clicking a button according to its name):

Button name (value) is submit
uses ...OleCtrls, SHDocVw, MSHTML;

procedure TForm1.FormCreate(Sender: TObject);
var Url, Flags, TargetFrameName, PostData, Headers: OleVariant;
begin
  Url := ExtractFilePath(Application.ExeName) + 'Test.htm';
  WebBrowser1.Navigate2(Url, Flags, TargetFrameName, PostData, Headers);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  doc: IHtmlDocument2;
  i: integer;
  ov: OleVariant;
  disp: IDispatch;
  collection: IHTMLElementCollection;
  inputelement: HTMLInputImage;
begin
  WebBrowser1.ControlInterface.Document.QueryInterface(IHtmlDocument2, doc);
  if not Assigned(doc) then
  begin
    Exit;
  end;
  ov := 'INPUT';
  disp := doc.all.tags(ov);
  if Assigned(disp) then
  begin
    disp.QueryInterface(IHTMLElementCollection, collection);
    if Assigned(collection) then
    begin
      for i := 1 to collection.Get_length do
      begin
        disp := collection.item(pred(i), 0);
        disp.QueryInterface(HTMLInputImage, inputelement);
        if Assigned(inputelement) then
        begin
          if inputelement.Name = 'submit' then
          begin
            inputelement.Click;
          end;
        end;
      end;
      end;
  end;
end;

Open in new window

The code's taken from DevShed Forums so don't forget to check the original page for more info.

------------------------------------------------------------------------------------------------------------------------------------------------------------

The second way is submitting data to the webpage.
But we can only guess what does the button do... if the it is supposed to send some data to the webpage via GET or POST method the code'd look kinda like this:
<form method="POST">
	<input type="text" name="data" value="data_value">
	<input type="submit" value"Button">
</form>

Open in new window


According to the TieHTTP component this code would perform the same action as if you'd click the button:
iehttp1.RequestMethod := 'POST';
iehttp1.ExecuteURL('http://www.myserver.com/script1.php?data=data_value');

Open in new window

So you will have to find the input values inside the <form> tag and submit them to the webpage...
0
 
evilkidAuthor Commented:
cant use TWebBrowser

and it dosnt need a post .. like when u press it u get a message
thats it
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Geert GOracle dbaCommented:
you can use TWebBrowser
I don't see why you would only want to use such a component as TIEHTTP

You use the post command with that component
0
 
MorphorCommented:
If you need a message dialog to show up when you "click" the button then you have to know entire source code of the webpage - you didn't provide any so we can't help you...

So what exactly is supposed to happen when the button is "clicked"?
What is the entire source code of the webpage?
0
 
evilkidAuthor Commented:
@Morphor
well facebook got this page :
http://www.facebook.com/sharer/sharer.php to share stuff on the fb wall
and it has 2 parameters (i think)
u : the url
t : the default title of the link


now i want when the user click the button , he share something on his wall (supposing he s already connected)

i can use (ieHttp.executeURL('www.facebook.com/sharer/sharer.php?u=site.com&t=examlpe'))
but i still have to press that "share" button in the page
0
 
MorphorCommented:
Firstly, share.php uses GET method.

As you can see the POST method is processed via Javascript (AJAX) and there are additional parameters to be sent when you click the Share button:

The page data is sent to:
http://www.facebook.com/ajax/sharer/submit_page/?__a=1

Open in new window

The data itself:
post_form_id	
fb_dtsg	Ur0-x
UIPrivacyWidget[0]	
privacy_data[0][value]	
privacy_data[0][friends]	
privacy_data[0][list_anon]	
privacy_data[0][list_x_anon]	
friendTarget	
groupTarget	
message_text	YourMessage
message	YourMessage
attachment[type]	
src	
appid	
parent_fbid	
mode	
share	
lsd	
post_form_id_source

Open in new window


(Use Tamper Data to find out what is sent between you and the server)

So what you have to do is to load all these parameters and "POST" them to the server... Some parts of the data to be sent are constant and some of them are not. That's why I recomment using TWebBrowser (or you can do it the harder way if you really want to).

I bet the end user won't really care if the "FaceBook" application you're creating will show him share page or an edit with a button instead. Assuming you only want to make things for the end user easier and you are not creating an application that uses his wall without him even knowing about it...
0
 
evilkidAuthor Commented:
thx for ur reply
but i cant find most of the parameters in www.facebook.com/sharer/sharer.php nor in http://www.facebook.com/index.php 
and i have to send these parameters thought  sharer/sharer.php or ajax/sharer/submit_page/?__a=1 ?
 
and about the TWebBrowser , i can post the URL and Titel ?

and yea i told the user is already connected so he knows about it

thx

0
 
evilkidAuthor Commented:
ok thx i got it done with the WebBrowser :) thx
0
 
evilkidAuthor Commented:
thx ^^
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.