[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

make delphi press a button in a website?

Posted on 2011-05-06
10
Medium Priority
?
1,526 Views
Last Modified: 2012-05-11
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


0
Comment
Question by:evilkid
10 Comments
 
LVL 14

Assisted Solution

by:systan
systan earned 1000 total points
ID: 35706609
0
 
LVL 3

Accepted Solution

by:
Morphor earned 1000 total points
ID: 35707414
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
 

Author Comment

by:evilkid
ID: 35707597
cant use TWebBrowser

and it dosnt need a post .. like when u press it u get a message
thats it
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 35710274
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
 
LVL 3

Expert Comment

by:Morphor
ID: 35711621
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
 

Author Comment

by:evilkid
ID: 35718713
@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
 
LVL 3

Expert Comment

by:Morphor
ID: 35727300
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
 

Author Comment

by:evilkid
ID: 35727839
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
 

Author Comment

by:evilkid
ID: 35728446
ok thx i got it done with the WebBrowser :) thx
0
 

Author Closing Comment

by:evilkid
ID: 35728461
thx ^^
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Find out what you should include to make the best professional email signature for your organization.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month19 days, 17 hours left to enroll

873 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