Link to home
Start Free TrialLog in
Avatar of PeterdeB
PeterdeBFlag for Netherlands

asked on

Autologin project needs an imagebutton click instead of a text button click (which I fail to implement)

Hi Guyzz!!

Some of you will remember me nagging about the autologin project  I was working on recently, so I'll post my code and point out where I run into a problem:

function TForm1.Go1:boolean;
var
  ShellWindow: IShellWindows;
  WB: IWebbrowser2;
  spDisp: IDispatch;
  IDoc1: IHTMLDocument2;
  Document: Variant;
  k, m: Integer;
  ovElements: OleVariant;
  i: Integer;
begin
result:=false; //assume no go

 ShellWindow := CoShellWindows.Create;
  // get the running instance of Internet Explorer
  for k := 0 to ShellWindow.Count do
  begin
    spDisp := ShellWindow.Item(k);
    if spDisp = nil then Continue;
    // QueryInterface determines if an interface can be used with an object
    spDisp.QueryInterface(iWebBrowser2, WB);
    if WB <> nil then
    begin try

      WB.Document.QueryInterface(IHTMLDocument2, iDoc1);
      except
      end;
      if iDoc1 <> nil then
      begin
        WB := ShellWindow.Item(k) as IWebbrowser2;
        begin
          Document := WB.Document;
          // count forms on document and iterate through its forms
          for m := 0 to Document.forms.Length - 1 do
          begin
            ovElements := Document.forms.Item(m).elements;
            // iterate through elements
            for i := 0 to ovElements.Length - 1 do
            begin
              // when input fieldname is found, try to fill out
              try
                if (CompareText(ovElements.item(i).tagName, 'INPUT') = 0) and
                  (CompareText(ovElements.item(i).type, 'text') = 0) then
                begin
                  ovElements.item(i).Value := edtUserName.Text;
                end;
              except
              end;
              try
                if (CompareText(ovElements.item(i).tagName, 'INPUT') = 0) and
                  (CompareText(ovElements.item(i).type, 'password') = 0) then
                begin
                  ovElements.item(i).Value := edtPassword.Text;

                end;
              except
              end;
              // when Submit button is found, try to click
              try
// This is where I'd like to press an imagebutton but all my attempts to grab hold of the d*mn thing failed . The code
// displayed here works with a normal button with a 'text element' > I use this code to login to several webpages and
// as long as the button has this text element (i.e. 'Log in' or 'Log mij in') it works. However I now bumped into the first
// page having an image button and studied Geobuls replies which helped me out the first time but currently I'm
// not using a TWebbrowser.            

if (CompareText(ovElements.item(i).tagName, 'INPUT') = 0) and   //  < here I d like to identify the image button
                   (CompareText(ovElements.item(i).type, 'SUBMIT') = 0) and  < so type should become: 'image'????
                  (ovElements.item(i).Value = edtButton.Text) then  < and what could I do here to get the right one????
                begin

                  ovElements.item(i).Click;
                  result:=true; // we're a go!

                end;
              except
              end;
            end;
          end;
        end;
      end;
    end;
  end;
end;

// Here's the html from the page btw:

<input type=image name="msuLoginSubmit" src="/images/loginButton.gif" alt="Log in" class=image>

I tried for several hours but couldnt get this thing working and kinda stumbled over the fact I dont use a TWebbrowser otherwise Geobuls code would have helped me out.
I hope its clear if not give me a sign and I'll explain.

My regards and max respect fly out to all-o-ya!!

Peter
ASKER CERTIFIED SOLUTION
Avatar of Russell Libby
Russell Libby
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PeterdeB

ASKER

Hi Russell! Thanks for your response!! You encourage me to fire up Delphi and continue where I left some days ago:)

I will get back to you > for now I'll be testing the code!

Thanks for the effort you put into assisting me!

Regards Peter
No problem Peter,

Just make sure to pull out the following in the above code:

    // Connect to the interface
     FEvents.ConnectTo(pvWeb2);

as it won't compile for you (clipped the code from another question I helped on).

Let me know if you run into any problems,
Russell

Hi Russell!!

Well mind me > I ran into the FEvents problem > but investigated some of the other projects I had been working on which lead me to use the ie_events.pas file > so my guess would be you're the one who helped out Carzzkiss who was assisting me:)

I even got a complete working project back then but at that moment I was facing a totally different problem so I left the project  he sent and moved on with the problem I was focussing on. So I just 'discovered' that the project he sent (coming from you or the both of you) seamlessly logged in at the sites my other project failed to log in. I did not succeed in implementing the code you supplied in this topic but you helped me out anyway since I owuld never have gone looking for that old program since I really didnt know it solved my problem.

Ofcourse I could be wrong assuming you were the one who assisted Carzkiss but the code was almost completely identical nevertheless you get the points to this question since my problem is solved now.

I hope this all doesnt sound to complicated > I just want you to know I didnt get the code you supplied to work but the project I was sent by Carzkiss (with code very very much alike yours or even pressumably yours) deals with my problem and you are the one who encouraged me to find a solution which I found...

My regards a big thank you for the effort you put into assisting me!

I will be posting some more questions regarding this login project Im working on until Im completely satisfied with it.

Max respect fly out to all-o-ya!!

PeterdeB

I'm sure Wayne will back me up on this, but the code is mine. ;-)

https://www.experts-exchange.com/questions/21216625/Points-for-rllibby-Login-to-IE-Instance-without-TWebBrowser-Straight-IE-Interface.html

Glad you have things in order, let me know if you run into other problems, as Im sure I can help you out. (I also wrote the ie_events.pas file)


Kind regards,
Russell
Ok then I'm talking to the right person >  I will post another  question > a rather huge one but I'll  reward it generously. I feel I've almost reached satisfaction just a few issues which require some attention so now is the moment for me to complete my project:)

Regards from PeterdeB

Ps could I have your emailaddress > t.bommel@chello.nl is mine > I have some questions about your component
rllibby.
  Yep, the code assist was from Russell.
I like many others on EE, use others information to assist others.
It is the only way to assist and help everyone in the group.
If we did not, then there would be a lot more unanswered posts in EE.
Of which hopefully everyone will be able to assist everyone.
So that no one goes without assistance.

Take Care all;
Carrzkiss
Such cooperation improves the quality and lifts the level of assistance you can offer to others who are in need of help. I can testify on that! EE in fact relies on that cooperation between wizardzz like you guys!!

Regards and respect!!

Peter
Aha and to avoid misunderstanding > I accidentally logged in as Fdehell, being Frank my twinbrother who occassionally uses my pc when he visits me. So these replies come from Peter, logged in as Fdehell.


We are twins, the magic touch never ends....:)


Regards Peter
:-)
Take care. maybe you twins can meet the "Olson Twins" :p

Take Care
LOL :)

Regards Peter