Jump to content

Trouble With IE Button Click


Recommended Posts

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)
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

@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
Link to comment
Share on other sites

@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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

  • Moderators

Maggotus,

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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.

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

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!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...