Jump to content

recognize website input boxes when clicked

- - - - -

  • Please log in to reply
18 replies to this topic

#1
ployo60

ployo60

    Newbie

  • Members
  • PipPip
  • 28 posts
I want to create a program that recognizes when you click in a inputbox on a website in your browser. I have discussed this with someone already and thought that it would be best with Twebbrowser, but i dont really want to recreate an entire webbrowser just for this purpose, anyone can help? im very interested in the selecting with the mouse of inputtextboxes of a website and find thing the information about that text box, so i can fill it in with a program. Thx!!!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Can you offer a little more detail on what you're trying to do? What you've said is extremely vague, and could have a variety of solutions depending on the details of what your doing, the website being discussed, etc.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
ployo60

ployo60

    Newbie

  • Members
  • PipPip
  • 28 posts
I have dropped the steps down below.
1. Define the website (could be any, i want this to be variable, so you can do it for multiple sites)
2. Select the prefered inputbox on the website with the mouse
3. Find the information of that inputbox, like name and value.... and place this in a memobox to see
4. Type in the input box on the webite and then have the value of the input box change in the memobox.

These are the first steps to the program. It would be best if i didnt have to use Twebbrowser so i dont recreate an entire web browser. Select these inputboxes from chrome,firefox,IE......
Hope that makes it more clear :)

#4
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
Usually we do steps 1 to 3 manually by analyzing the html source of the page. From the source you will get the input fields names (and default values). Do you want to develop a tool to make this process easier?

Quote

It would be best if i didnt have to use Twebbrowser so i dont recreate an entire web browser

Actually you don't have to use TWebBrowser for this. You could also use FireFox embedded. TWebBrowser itself is IE embedded to your program. But the key point is that your program must be able to "hook" into the web browser that you want to use. Without this, you could not get reliable information. For example, usually we can get the values of edit boxes of another program if the edit boxes were windows edit control. But you can't do this with FireFox, since I believe they develop their own edit control that does not follow Windows standard edit control behavior. Therefore there is no way for external application to get values inside them without using api provided by FireFox. Hence you need to use to use embedded FireFox to be exposed to the "api".

Anyway, it would take only an hour or two to create "basic full" web browser from TWebBrowser. :)

#5
ployo60

ployo60

    Newbie

  • Members
  • PipPip
  • 28 posts
ok, so with firefozx its not that easy unless you do an embedded version. And i agree on the hooking on to the web browser used at the time, often that would be the default browser. I want to know how i got about making a program that can hook into the default browser(not being firefox). Whenever you are hooked into it, you can find the information about the current webpage..... that would be the start. guess the question is how?

#6
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
I think you've got me wrong. By "hook" I mean our program can manipulate the web browser. I am stressing that it is the key point since not all web browsers allow us to do that. To my knowledge it's only IE (through TWebBrowser control if we are using Delphi) and FireFox embedded (you must install the custom control yourself, I don't have actual experience on this). So we can not simply hook to default browser.

What I mean is we have to embed a web browser that we can hook into. Consider the instance of this web browser as part of our program. And currently our options are TWebBrowser and FireFox embedded. Let's forget FireFox embedded for now. Let's focus on TWebBrowser.

You can build a 'full' web browser by dropping a TWebBrowser in a form of your Project and add some other controls to control or show information of the TWebBrowser. For example add TEdit to show the current url, add refresh button, back and forward buttons, menus, etc so the form looks like a decent web browser. Now the users must use this web browser to fill the web form. This way your program (i.e. actually the web browser) can inspect what is the current active field and its information. It is then up to your design how do you want to handle the information.

Again, the user must use our web browser, not the default.

For exercise, why don't you open Delphi and try to build the browser. I believe you will progress a lot with your understanding on the project.

#7
ployo60

ployo60

    Newbie

  • Members
  • PipPip
  • 28 posts
I agree completely with what you say. Play around with TWebBrowser and see how it works, but i have done that before, thats why i started a forum, I don't know how to find the active field. Like you say, "This way your program (i.e. actually the web browser) can inspect what is the current active field and its information." This is the main thing and i dont know how to do this. Not sure what functions and procedures to use for this.

#8
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
Now that we cleared things up and focus on TWebBrowser...

Since TWebBrowser in reality is a wrapper to IE from Microsoft which using ActiveX to provide access to their controls then we need information of supported ActiveX interfaces of IE. TWebBrowser itself only surfaces the most common properties and method. Advance features available only through calls via the interfaces. Fortunately most, if not all, interfaces for IE is already defined/provided in MSHTML unit. For official information, please visit this link on MSDN on MSHTML.

Now for a sample code, the following code will find input field of the specified name of specified form name then if the field is found will fill it with the given value. You have to add MSHTML to your uses list to be able to use the interfaces.


function FindWebForm(const AWebBrowser: TWebBrowser; const AName: string; out AWebForm: IHTMLFormElement): Boolean;

var

  vForms: IHTMLElementCollection;

  vForm : IHTMLFormElement;

  i     : integer;

begin

  Result := False;

  if AWebBrowser.Document=nil then

    Exit;

    

  vForms := (AWebBrowser.Document as IHTMLDocument2).Forms as IHTMLElementCollection;

  for i := 0 to vForms.Length - 1 do

  begin

    vForm := vForms.Item(i, 0) as IHTMLFormElement;

    Result := UpperCase(vForm.name) = UpperCase(AName);

    if Result then

    begin

      AWebForm := vForm;

      Break;

    end;

  end;

end;


function FillWebFormField(const AWebBrowser: TWebBrowser; const AFormName, AFldName, AFldValue: string): Boolean;

var

  vForm: IHTMLFormElement;

  vField: IHTMLElement;

begin

  Result := FindWebForm(AWebBrowser, AFormName, vForm) and (vForm <> nil);

  if Result then

  begin

    vField := vForm.Item(AFldName, '') as IHTMLElement;

    Result := vField <> nil;

    if not Result then

      Exit;


    if vField.tagName = 'INPUT' then

      (vField as IHTMLInputElement).value := AFldValue

    else if vField.tagName = 'SELECT' then

      (vField as IHTMLSelectElement).value := AFldValue

    else if vField.tagName = 'TEXTAREA' then

      (vField as IHTMLTextAreaElement).value := AFldValue

    else

      Result := False;

  end;

end;



#9
ployo60

ployo60

    Newbie

  • Members
  • PipPip
  • 28 posts
yep, I have found this online before as well, but for this we need to know th specific name of the field and I don't know that from a random webpage. It is exactly like you said in your last post, "inspect the current active field and its information". how do we do this?

and im not sure if i understand this completely:

if vField.tagName = 'INPUT' then
(vField as IHTMLInputElement).value := AFldValue
else if vField.tagName = 'SELECT' then
(vField as IHTMLSelectElement).value := AFldValue
else if vField.tagName = 'TEXTAREA' then
(vField as IHTMLTextAreaElement).value := AFldValue
else
Result := False;

#10
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts

ployo60 said:

It is exactly like you said in your last post, "inspect the current active field and its information". how do we do this?

Well, that line was for illustration only :c-whistle:. While I really think we can do that, but honestly I don't know for sure how. No experience in doing it, since up to now I never need it. You have to explore interfaces in MSHTML unit or in msdn to see if you can get that information. Either by event (or messages or callback) or by polling.

Quote

if vField.tagName = 'INPUT' then

this to check if the field is a simple edit box.

Quote

else if vField.tagName = 'SELECT' then

this is to check if the field is a combobox.

Quote

if vField.tagName = 'TEXTAREA' then

This is to check if the field is a memo box.

Quote

(vField as IHTMLTextAreaElement).value := AFldValue

While this one is setting the value to the field

#11
ployo60

ployo60

    Newbie

  • Members
  • PipPip
  • 28 posts
I'll look into that, maybe start a new forum, i'll drop u the link.

What is we do the following, we drop two TWebBrowsers on one form, each with their own url editbox and go button. Say we bring them one to google (Twebbrowser1) and the other one to yahoo.com (Twebbrowser2). I want to type in google, 'hello world' and i want that to be typed through this program into the search bar of yahoo.com as well. how would you go about doing that?

#12
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
My solution would be:
  • Find out the search bar form and input field names of yahoo and google by inspecting the html source.
  • Create the program with two TWebBrowsers like your plan.
  • Users do not enter their search words directly in any of the web page. They type the searched words into a special TEdit.
  • After they press Enter or click search button (also our own from TButton), then our program will enter the searched words into both pages and "click" the search button.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users