Sign in to follow this  
Followers 0

Trouble With IE Button Click

20 posts in this topic

Posted

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!

#AutoIt3Wrapper_run_debug_mode=Y
#include <IE.au3>
;~ Dim $sUsername = $CmdLine[1]
;~ Dim $sPassword = $CmdLine[2]
;~ Dim $sCompanyCode = $CmdLine[3]
$sURL = "https://www.gotimeforce2.com/tfiiredirector"
$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)

Share this post


Link to post
Share on other sites



Posted

Please read this thread...

Share this post


Link to post
Share on other sites

Posted

Please read this thread...

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?

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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...

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted (edited)

@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

Share this post


Link to post
Share on other sites

Posted (edited)

@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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

Maggotus,

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

M23

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.