Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Trouble With IE Button Click


  • Please log in to reply
19 replies to this topic

#1 Maggotus

Maggotus

    Seeker

  • Active Members
  • 11 posts

Posted 28 June 2012 - 06:46 PM

Hey Everyone -

I'm somewhat new to AutoIT and very new to using it to interact with IE.

I'm working with a website where I cannot simulate a mouseclick on the login button. I've been searching the forums for a few days, and have tried every possibility that i can understand to do. I'm somewhat of a novice at scripting, but i do have a little experience. So far, the only method I've found to press 'Login' is to tab and send ENTER - but i know that's unreliable.

When I've tried _IEAction($oLoginButton, "click") - it does nothing, but also doesn't return any error. I've also tried obtaining focus using _IEAction and sending ENTER, but that never appears to obtain focus. I even tried a copy/paste of code along these lines:

$hwnd = _IEPropertyGet($oIE, "hwnd") ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")


but truthfully, i don't fully understand this method, and likely never appropriately massaged it for this page.

I'm hoping someone can help me in the right direction. The credentials provided should throw an invalid login error - which would be great if I could even get it that far. Thanks in advance!

Plain Text         
#AutoIt3Wrapper_run_debug_mode=Y #include <IE.au3> ;~ Dim $sUsername = $CmdLine[1] ;~ Dim $sPassword = $CmdLine[2] ;~ Dim $sCompanyCode = $CmdLine[3] $sURL = "<a href='https://www.gotimeforce2.com/tfiiredirector' class='bbc_url' title='External link' rel='nofollow external'>https://www.gotimeforce2.com/tfiiredirector"</a> $sUsername = "test" $sPassword = "test" $sCompanyCode = "test" $oIE = _IECreate($sURL) WinSetState("[ACTIVE]", "", @SW_MAXIMIZE) $oForm = _IEFormGetCollection($oIE, 0) $oUsername = _IEFormElementGetObjByName($oForm, "usernamex") $oPassword = _IEFormElementGetObjByName($oForm, "passwordx") $oCompanyCode = _IEFormElementGetObjByName($oForm, "companycodex") $oLoginButton = _IEGetObjById($oIE,"submit") _IEFormElementSetValue($oUsername, $sUsername) _IEFormElementSetValue($oPassword, $sPassword) _IEFormElementSetValue($oCompanyCode, $sCompanyCode) Send("{TAB 9}") Send("{Enter}") _IELoadWait($oIE)








#2 MrMitchell

MrMitchell

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 747 posts

Posted 28 June 2012 - 06:49 PM

Please read this thread...
http://www.autoitscript.com/forum/topic/141527-auto-login-a-site-with-autoit/

#3 Maggotus

Maggotus

    Seeker

  • Active Members
  • 11 posts

Posted 28 June 2012 - 06:56 PM

Please read this thread...
http://www.autoitscript.com/forum/topic/141527-auto-login-a-site-with-autoit/


Hmm - i see your point. My problem isn't really the login process, it's the maintenance i have to do within our software once i get in, this just happens to be the only public page that others could see the source. I was going to assume that whatever methods i could use to press this button, could also be used to press the buttons that will allow me to run maintenance within the site.

Is there another way to pose the question where it doesn't appear to violate the rules?

#4 MrMitchell

MrMitchell

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 747 posts

Posted 29 June 2012 - 01:31 PM

After you manually log in are you having issues automating the rest of the site?

I guess it just depends how the buttons are implemented...though if you are having a hard time with it, it might be because the site's designers intended to make it difficult to be automated :D

#5 Maggotus

Maggotus

    Seeker

  • Active Members
  • 11 posts

Posted 29 June 2012 - 03:13 PM

I'm only having trouble with the button clicks - everything else is fine.

I'll rescind my earlier request for help with pushing the 'login' button - and I'm hoping someone can help me with clicking this new button.(I'm new to posting in this forum, and not sure whether this would warrant a new topic)

<input type="button" id="RecalculateCompanyButton" class="ButtonBasic" value="GeneralForm.RecalculateEmployeeListText" onclick="recalCompany('63','This will remove all verifications for all employees during this pay period, and could take over 30 minutes to complete.\n\rAre you sure you wish to continue?')" />


Here is the code I am currently using to press the button:

Send("+{TAB}") Sleep(500) Send("+{TAB}") Sleep(500) Send("+{TAB}") Sleep(500) Send("+{TAB}") Sleep(500) Send("+{TAB}") Sleep(500) Send("+{TAB}") Sleep(500) Send("{Enter}")


Before when i tried to Send("+{TAB 6}") it wouldn't always land on the button. This method is very visible and takes a long time, and i'm still not confident in the results. I've also tried using the following:

$oButton = _IEGetObjById ($oIE, "RecalculateCompanyButton") if @error = 0 Then msgbox(0,"",$oButton.value) EndIf _IEAction($oButton, "click")


And this actually pops up the msgbox with the label of the button (which makes me think i've got the right object) - but alas, it still doesn't actually click the button. Using a similar method, I tried using the "focus" action, then sending ENTER, and got the same results.

As to whether the developers made it difficult to automate - it is possible, but I don't think so. They were the ones that approached me to create a band-aid for a client while a permanent solution goes through the long haul of the development queue.

I really appreciate help anybody could provide.

#6 MrMitchell

MrMitchell

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 747 posts

Posted 29 June 2012 - 03:20 PM

It looks like you have to click the "recalculate" button then click yes in a confirmation message?

#7 Maggotus

Maggotus

    Seeker

  • Active Members
  • 11 posts

Posted 29 June 2012 - 03:34 PM

It looks like you have to click the "recalculate" button then click yes in a confirmation message?


Yes - but the confirmation box doesn't even pop up when I use the above methods.

#8 jdelaney

jdelaney

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,112 posts

Posted 29 June 2012 - 03:53 PM

please don't automate using tabs :D...use the _ie.* functions.
IEbyXPATH-Grab IE DOM objects by XPATH
IEscriptRecord-Makings of an IE script recorder
ExcelFromXML-Create Excel docs without excel installed
GetAllWindowControls-Output all control data on a given window.

#9 MrMitchell

MrMitchell

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 747 posts

Posted 29 June 2012 - 04:00 PM

please don't automate using tabs :D...use the _ie.* functions.


If you read the whole thread you'd know he's currently using that method now but trying to get away from it...

#10 jdelaney

jdelaney

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,112 posts

Posted 29 June 2012 - 06:10 PM

One unproductive post to point out another, nice.

anywho- Would you post the HTML of the button, and all it's sub elements? Sometimes, you must focus on a lower level than the actual <button> it's self.
IEbyXPATH-Grab IE DOM objects by XPATH
IEscriptRecord-Makings of an IE script recorder
ExcelFromXML-Create Excel docs without excel installed
GetAllWindowControls-Output all control data on a given window.

#11 MrMitchell

MrMitchell

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 747 posts

Posted 29 June 2012 - 08:12 PM

@jdelaney - My apologies.

As for original issue, I looked at it again and figure OP must be getting the correct object, and actually clicking the button but it's not firing the javascript. This function "recalCompany" would be Javascript, correct?

Does this work? (you mentioned it but didn't provide exact code you used):
$hWinIE = _IEPropertyGet($oIE, "hwnd") $oButton = _IEGetObjById ($oIE, "RecalculateCompanyButton") _IEAction($oButton, "focus") ControlSend($hWinIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")


Maybe also try ControlSend without specifying ControlID?

Edited by MrMitchell, 29 June 2012 - 08:13 PM.


#12 Maggotus

Maggotus

    Seeker

  • Active Members
  • 11 posts

Posted 30 June 2012 - 12:47 AM

@MrMitchell -

Tried what you provided, and still got no results. i also changed the last line of code to

ControlSend($hWinIE, "", "", "{Enter}")


to see if it would make a difference and still nothing. There is no visible change when I use the
_IEAction($oButton, "focus")

command - shouldn't there be a visual cue that the button has obtained focus - similar to when you tab to the button? Also, yes - it appears to be Javascript - but i'm no developer, just a project manager with some experience with scripting and automating.

Also - @jdelaney I'm not very experienced with HTML and don't know how to find whether a button has "sub elements". If you could point me in a direction that will tell me how to discover the sub elements, I'd be more than happy to provide. I'm not comfortable with posting the entire HTML of this particular page, but I will provide whatever will help if i can peel out the right pieces. More than likely this button has the same basic structure as the button found on the main http://www.gotimeforce2.com web page. That may provide us with some insight on what i could be missing here.

Edited by Maggotus, 30 June 2012 - 12:51 AM.


#13 Maggotus

Maggotus

    Seeker

  • Active Members
  • 11 posts

Posted 30 June 2012 - 04:08 PM

I found this in the source - may confirm that the button triggers a javascript event?
<script src="../JavaScript/RecalculateCompany.js" type="text/javascript"></script>


The button
<input type="button" id="RecalculateCompanyButton" class="ButtonBasic" value="GeneralForm.RecalculateEmployeeListText" onclick="recalCompany('63','This will remove all verifications for all employees during this pay period, and could take over 30 minutes to complete.\n\rAre you sure you wish to continue?')" />

appears to call this command(?):
function CreateCommand(id, elementId){ switch(id){ case '63': var command = new Ajax.Commands.RecalculateCompany(elementId,id,counter); net.Base.addCommand(command); }


The only other items i found in the source relating to recalculate company was a progress bar, and didn't seem to be helpful.

#14 MrMitchell

MrMitchell

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 747 posts

Posted 01 July 2012 - 10:00 PM

It's a long shot but try using this in place of where you would click the button.

$oIE.document.parentWindow.execScript("recalCompany('63','This will remove all verifications for all employees during this pay period, and could take over 30 minutes to complete. Are you sure you wish to continue?')","javascript")


I've seen this method before but I am having trouble finding documentation for how to use it fully.

Edited by MrMitchell, 01 July 2012 - 10:46 PM.


#15 Maggotus

Maggotus

    Seeker

  • Active Members
  • 11 posts

Posted 14 July 2012 - 12:33 AM

So, the good news is that your method appears partially to do what I need it to, and pops up the dialog box. The downside is that the script halts execution until i manually click OK or Cancel.

I've tried using AdLibRegister- but that doesn't appear to fire when this is used... it appears that even it is halted after calling the command. Due to the fact that AutoIt is not multi-threaded, i'm not sure how i can proceed with this method.

#16 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 665 posts

Posted 14 July 2012 - 12:49 AM

Uhm...
Unless you didn't scroll:

thanhphuc,

Welcome to the AutoIt forum. :)

Unfortunately you appear to have missed the Forum Rules on your way in. Please read them now - particularly the bit about not discussing login methods - and then you will understand why this thread will now be locked. :naughty:

See you soon with some legitimate codeI hope. :)


M23


Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#17 Maggotus

Maggotus

    Seeker

  • Active Members
  • 11 posts

Posted 14 July 2012 - 01:14 AM

Uhm...
Unless you didn't scroll:


I think you probably just didn't read the whole thread. My problem is deeper, and is no longer directed at the login screen.

#18 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,811 posts

Posted 14 July 2012 - 06:52 AM

Maggotus,

I agree you have moved on and I am happy for the thread to continue. :)

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#19 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 665 posts

Posted 15 July 2012 - 12:57 AM

I think you probably just didn't read the whole thread. My problem is deeper, and is no longer directed at the login screen.

No i didn't, i just asumed you were still trying to login so didn't read it.
Sorry about that.
Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#20 MrMitchell

MrMitchell

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 747 posts

Posted 15 July 2012 - 08:29 AM

So, the good news is that your method appears partially to do what I need it to, and pops up the dialog box. The downside is that the script halts execution until i manually click OK or Cancel.

I've tried using AdLibRegister- but that doesn't appear to fire when this is used... it appears that even it is halted after calling the command. Due to the fact that AutoIt is not multi-threaded, i'm not sure how i can proceed with this method.


Can you look in the site's js file for the recalComany function and find out how to call it with an option to bypass confirmation dialog and just tell it to proceed without further user interaction? Right now you're calling it with two parameters but I only put that because that's what in the example you provided. Maybe if you adjust that '63' to another flag it might work...I dunno. Need that code!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users