Jump to content

Inconsistent results with AutoIt script


Recommended Posts

Hi All

I have developed a script to automate IE 9 file download.

- hook the notification bar

- wait till the download completes

-close the notification bar

Script is available here

https://gist.github.com/3016355

This scripts working fine 97 times out of 100 times. Sometimes it is failing to identifying the controls or perform events on control in Save as window and sometimes it is failing to hook the notification bar. What could be the possible reason for inconsistency?

Thanks

Srinivas

Link to comment
Share on other sites

Why don't you use function INetGet?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

and the rest of the _IE family of functions.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

I'm sure it's a timing issue.

I've found things like focusing or clicking on a dropdown menu can cause a webpage to go briefly inactive while it loads additional data. Does anything you're doing cause the page to "wink" for a moment? Try inserting some strategically placed WinWaitActive() statements...

Link to comment
Share on other sites

Try using this to get the URL from the link, then pass it to InetGet()

#include <IE.au3>

$url = "http://UrlOfPageWhereDownloadLinkExists" ; insert your page url where the link exists
$oIE = _IECreate($url)
$oLink = _IEGetObjById($oIE, "DOM_object_id_of_link") ; insert the DOM object id of the download link in question. If it has a unique DOM name, you can use _IEGetObjByName() instead.
$sUrl = _IEPropertyGet($oLink, "outerhtml")
$iStr = StringInStr($sUrl, "href=") ; Where does the href start
$sMidString = StringMid($sUrl, $iStr) ; Extract everything from href to end of string
$asString = StringSplit($sMidString, '"') ; Split it with " as delimiter
$sString = $asString[2] ; re-compose the string with only the href parameter. For the sake of the example, I output it it to its own variable. However you can call it with just $asString[2].
msgbox(0,"",$sString) ; Check output

EDIT: Added notes to code and removed the quotes that were inserted into $sString

Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Post #10, I have an example of using InetGet() and making your own progress bar.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Like I said , we can't know the file download URL because it is a server side redirect in response to a form submission

I am not posting the response headers but below is intermediate redirect page HTML.

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="download.aspx%3ffile%3df6347457-e261-4f25-943c-9088b2a45562.csv%26mime%3dapplication%2foctetstream">here</a>.</h2>
</body></html>

Note: I am using selenium for web page automation.

Link to comment
Share on other sites

Let me be more specific about my issue

File Download script

;Author: Srinivasa Pulagam
#include "common.au3"
_init();
;read arguments
Local $pathToSave=$CmdLine[1]
; intialize variables
Local $timeOut=180;in seconds
Local $saveAsTimeOut=60; in seconds
Local $fileDownloadTimeOut=300; in seconds
logInfo("File path " & $pathToSave & @CRLF)
; wait for file download dialog to appear
if WinExists("File Download") then
; activate file download dialog
logInfo("File Download dialog found" & @CRLF);
WinActivate("File Download")
else
If WinWait("File Download","",$timeOut) =0 then
logInfo("Timed out while waiting for File Donwload dialog" & @CRLF);
exit(1)
EndIf
; activate file download dialog
tc(WinActivate("File Download"),"Activate File Download dialog",true,0);
EndIf
;click save button
tc(ControlClick("File Download","","CLASS:Button;INSTANCE:2]"),"Click on save button",true,0);
; wait for Save As window
If WinWait("Save As","",$saveAsTimeOut)=0 then
logInfo("Timedout while waiting for Save As window" & @CRLF);
exit(1)
EndIf
; activate Save As window
tc(WinActivate("Save As"),"Activate Save As window",true,0);
; path to save the file is passed as command line arugment
tc(ControlFocus("Save As","","[CLASS:Edit;INSTANCE:1]"),"Focus on File path edit box",true,0);
Send($pathToSave)
;click on save button
tc(ControlClick("Save As","","[CLASS:Button;INSTANCE:2]"),"Click on Save button",true,0);
; wait till file download dialog closes
tc(WinWait("Download complete","",$fileDownloadTimeOut)," Wait till download completes",true,0);
tc(WinClose("Download complete","") ,"Close Download complete window",true,0);
tc(WinWaitClose("Download complete","",$saveAsTimeOut),"Wait till Download complete window disappears",true,0);
logInfo("-------------------------------------------------" & @CRLF);
_fini();

Common.au3

#include-once
Dim $logfile;
Func _init()
$logfile=FileOpen(@ScriptDir & "/logs/autoit.log", 1);
EndFunc
Func tc($conditon,$message,$stopTest,$failure)
if $conditon=$failure then

FileWrite($logfile,$message & ": Failed" & @CRLF);

if $stopTest Then

Exit(1);
EndIf
Else
FileWrite($logfile,$message & ": Passed " & @CRLF);
EndIf

EndFunc
Func logInfo($message)
FileWrite($logfile,$message )
EndFunc
Func _fini()
FileClose($logfile);
EndFunc

Sometimes (3 out of 100) I see this command

ControlClick("Save As","","[CLASS:Button;INSTANCE:2]")

returning 1 and actually no click event being performed on the button. That is my issue.

Edited by Ind007
Link to comment
Share on other sites

Possibly the click is too fast for the button?

Try adjusting Opt("MouseClickDownDelay") for a slight increase in delay for how long the mouse-click is held down.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

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