Jump to content

"Save As" Not Working In Hidden Internet Explorer - (Moved)


Recommended Posts

Hi all, I have problem when transforms console app into service. My service will trigger IE  to automate save as but stuck when save as process. 

Attach is the working code for origin console app:

Local $fileName = _GetFileName($oRow, $FileName_Column_index)
         Local $Download_status = _Execute($oRow, "Download", "focus")

         If ($Download_status = 1) Then
            _writeLog("Success to click Download")
         Else
            _writeLog("Failed to click Download")
            exitProgram(5)
         EndIf
         resetState($windowTitle)

         local $saveStatus = _SaveAsAndWait($fileName)
         If ($saveStatus = 1) Then
            _writeLog("Success to save")
            exitProgram(0)
         Else
            _writeLog("Failed to save")
            exitProgram(5)
         EndIf

Problem when in _SaveAsAndWait function below; forever in _writeLog("waiting download completed") loop:

Func _SaveAsAndWait($fileName, $timeOut = 15*60*1000)

    $windowTitle = _IEPropertyGet($oIE, "title")
    Sleep(5000)
    Send("{SHIFTDOWN}")
    Sleep(500)
    Send("{F10}")
    Sleep(500)
    Send("{SHIFTUP}")
    Sleep(500)
    Send("a")
    Sleep(500)
    Send("{Enter}")
    Local $timer = TimerInit()
    While(Not WinActivate("Save As"))
        Sleep(1000)
        If(TimerDiff($timer) > 60*1000) Then
            _writeLog("Window [Save As] not found")
            exitProgram(5)
        EndIf
    WEnd

    Sleep(2000)
    Local $asd = ControlSetText("Save As", "", "[CLASS:Edit; INSTANCE:1]", $downloadPath& "\" &$fileName)
    _writeLog("Send <"&$downloadPath& "\" &$fileName&"> as download path")
    Send("{ENTER}")
    Sleep(2000)
    $windowTitle = _IEPropertyGet($oIE, "title")
      resetState($windowTitle)
    If  (WinActivate("Confirm Save As")) Then
        _writeLog("download Failed, file already exist")
        Send("n")
        Sleep(500)
        Send("{ESC}")
        Return 0
    EndIf

    Local $fileThr = false
    Local $timer = TimerInit()
    While(Not FileExists($downloadPath& "\" &$fileName))
        _writeLog("waiting download completed")
        Sleep(1000)
        If (TimerDiff($timer)> $timeOut) Then
            _writeLog("download Failed, wait too long")
            Return 0
        EndIf
    WEnd

    _writeLog("download success")
    Return 1
   IEexist_2()
EndFunc

 Here is my currrent code:

Func _SaveAsAndWait($fileName, $timeOut = 15*60*1000)

    $windowTitle = _IEPropertyGet($oIE, "title")
    Sleep(5000)
    ControlSend("[CLASS:IEFrame]","","","{SHIFTDOWN}")
    Sleep(500)
    ControlSend("[CLASS:IEFrame]","","","{F10}")
    Sleep(500)
    ControlSend("[CLASS:IEFrame]","","","{SHIFTUP}")
    Sleep(500)
    ControlSend("[CLASS:IEFrame]","","","a")
    Sleep(500)
    ControlSend("[CLASS:IEFrame]","","","{Enter}")
   Sleep (1000)
   Local $sClassList = WinGetClassList("[CLASS:IEFrame]")
_writeLog("list  CLASS: "&$sClassList )
    Local $timer = TimerInit()
    While(Not WinExists("Save As"))
        Sleep(1000)
        If(TimerDiff($timer) > 60*1000) Then
            _writeLog("Window [Save As] not found")
            exitProgram(5)
        EndIf
    WEnd

    Sleep(2000)
    Local $asd = ControlSetText("Save As", "", "[CLASS:Edit; INSTANCE:1]", $downloadPath& "\" &$fileName)
    _writeLog("Send <"&$downloadPath& "\" &$fileName&"> as download path")
    Send("{ENTER}")
    Sleep(2000)
    $windowTitle = _IEPropertyGet($oIE, "title")
      resetState($windowTitle)
    If  (WinExists("Confirm Save As")) Then
        _writeLog("download Failed, file already exist")
        Send("n")
        Sleep(500)
        Send("{ESC}")
        Return 0
    EndIf

    Local $fileThr = false
    Local $timer = TimerInit()
    While(Not FileExists($downloadPath& "\" &$fileName))
        _writeLog("waiting download completed")
        Sleep(1000)
        If (TimerDiff($timer)> $timeOut) Then
            _writeLog("download Failed, wait too long")
            Return 0
        EndIf
    WEnd

    _writeLog("download success")
    Return 1
   IEexist_2()
EndFunc

The output:

list  CLASS: Frame Notification Bar
DirectUIHWND
BrowserFrameGripperClass
Client Caption
WorkerW
ReBarWindow32
TravelBand
ToolbarWindow32
Address Band Root
AddressDisplay Control
Edit
ToolbarWindow32
ToolbarWindow32
TabBandClass
DirectUIHWND
ControlBandClass
ToolbarWindow32
CommandBarClass
ReBarWindow32
Frame Tab
TabWindowClass
Shell DocObject View
Internet Explorer_Server
2020-07-05 17:22:44.530 :     Send <C:\Users\Documents\file_202007060122> as download path
2020-07-05 17:22:48.067 :     waiting download completed
2020-07-05 17:22:49.072 :     waiting download completed
2020-07-05 17:22:50.078 :     waiting download completed

--infinite of waiting download completed--

There is no file downloaded in specified path or download directory.

Please any idea or suggestion much welcome, thank you in advance.

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

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

A couple of things... :) 

1. You're getting the return value of ControlSetText, but you aren't checking if it's True or False... that'll let you know if you're finding the window and control or not.

2. You're using a lot of Send commands. Send directs the input to the active window, so if anything else pops up, your script will fail. At the very least, replace the Send("{ENTER}") with ControlClick("Save As", "", "[CLASS:Button; INSTANCE:2]") to click save (verify this is correct on your computer) instead of sending enter.

3. It looks like your timeout is 15 minutes... that's a bit long unless it's a huge file.

4. Usually if you input a file path like "C:\Users\Documents\file_202007060122", the Save As dialog will add an extension for you of the expected type. You might need to do a FileFindFirstFile search to get your result if you don't know the extension before you try to download it.

5. Welcome to forums! See if you can try the above and get it to work, but post back and let us know how it goes :)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Thanks for reply @seadoggie01 ,

I update my codes as following :

ControlSend("[CLASS:IEFrame]","","","{ALTDOWN}")
    Sleep(500)
    ControlSend("[CLASS:IEFrame]","","","n")
    Sleep(500)
    ControlSend("[CLASS:IEFrame]","","","{ALTUP}")
    Sleep(500)
    ControlSend("[CLASS:IEFrame]","","","{DOWN}")
    Sleep(500)
    Local $click = ControlClick("Save As", "", "")
    _writeLog("ControlClick return:" & $click )
   Sleep (1000)
   Local $sClassList = WinGetClassList("[CLASS:IEFrame]")
   _writeLog("list  CLASS: "&$sClassList )
    Local $timer = TimerInit()

    Sleep(2000)
    $search = FileFindFirstFile($downloadPath& "\*.*")
    If $search = -1 Then
    _writeLog("No files/directories matched the search pattern")
    Exit
 EndIf
   While 1
        $sFileName = FileFindNextFile($search)
        ; If there is no more file matching the search.
        If @error Then ExitLoop

        ; Display the file name.
        _writeLog("File: " & $sFileName)
   WEnd

    ; Close the search handle.
    FileClose($search)
    Local $asd = ControlSetText("Save As", "", "[CLASS:Edit; INSTANCE:1]", $downloadPath& "\" &$fileName)
    _writeLog("Send <"&$downloadPath& "\" &$fileName&"> as download path")
    _writeLog("ControlSetText return:" & $asd )
    ControlClick("Save", "", "[CLASS:Button]")

Result:

 ControlClick return:0
 list  CLASS: BrowserFrameGripperClass
Client Caption
WorkerW
ReBarWindow32
TravelBand
ToolbarWindow32
Address Band Root
AddressDisplay Control
Edit
ToolbarWindow32
ToolbarWindow32
TabBandClass
DirectUIHWND
ControlBandClass
ToolbarWindow32
CommandBarClass
ReBarWindow32
Frame Tab
InternetToolbarHost
WorkerW
ReBarWindow32
ToolbarWindow32
TabWindowClass
Shell DocObject View
Internet Explorer_Server
File: 202004290215_testing
File: 202005140205_testing
Send <C:\Users\Documents\202007072236> as download path
ControlSetText return:0
waiting download completed

So turns out like my controlsend and controlsend are not working initially at backgground.

Link to comment
Share on other sites

still stuck here, today the deadline but my "save as" windows still not exists even though link is confirmed clicked using

_IEAction($oElement, "click")

 And all control send return 1 

$handle = WinGetHandle("[CLASS:IEFrame]")
    _writeLog("result handle " &$handle)
    $hCtrl = ControlGetHandle($handle,"","[Class:DirectUIHWND]")
    _writeLog("result control handle " &$hCtrl)
    $altdown = ControlSend($handle,"","","{ALTDOWN}")
    _writeLog("result $altdown " &$altdown)
    Sleep(500)
    $sendN = ControlSend($handle,"","","n")
    _writeLog("result sendn " &$sendN)
    Sleep(500)
    $altup = ControlSend($handle,"","","{ALTUP}")
    _writeLog("result shift up " &$altup)
    Sleep(500)
    $down = ControlSend($handle,"","","{DOWN}")
    _writeLog("result down " &$down)
    Sleep(500)
    $down1 = ControlSend($handle,"","","{DOWN}")
    _writeLog("result down1 " &$down1)
    Sleep(500)
    Local $click = ControlClick("Save as", "", $hCtrl)
    _writeLog("ControlClick return:" & $click )
    $enter = ControlSend($handle,"",$hCtrl,"{Enter}")
    _writeLog("result enter " &$enter)

result

 Success to click Download
result handle 0x00640058
result control handle 0x005A0032
result $altdown 1
result sendn 1
result shift up 1
result down 1
result down1 1
ControlClick return:0
result enter 1

Any idea? Or should I make it as service. Currently another C++ exe make as service which trigger this autoit exe in background.

 

Link to comment
Share on other sites

You're looking for the file before clicking Save As... try saving it and then looking for the file :)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

7 hours ago, seadoggie01 said:

You're looking for the file before clicking Save As... try saving it and then looking for the file :)

Ouh I see. But as ControlSetText return:0, seems it not yet successful open save as windows. Wonder why already check clicking download link, supposed to have pop up save at the bottom, controlsend key work but still not found save as window. I check the file exist in 

While(Not FileExists($downloadPath& "\" &$fileName))
        _writeLog("waiting download completed")
6 hours ago, jguinch said:

are you sure that your service can interact with the user ?

This autoit exe is not service but another C++ exe was. As C++ exe triggering this autoit exe, it made autoit exe run in background too. Not sure why. But for C++ exe service is being ticked to Interact with desktop already. Are there any method to assure my app able to interact with user @jguinch ?  

 

Edited by triple_N
Link to comment
Share on other sites

with a service or program running as system account, not sure you can do that.

the good way is to avoid the use of a browser. There are at lot of topics on the forum. Search for WinHttpRequest

 

Link to comment
Share on other sites

 

3 hours ago, jguinch said:

with a service or program running as system account, not sure you can do that.

the good way is to avoid the use of a browser. There are at lot of topics on the forum. Search for WinHttpRequest

 

I found this thread ie11-save-as-for-file-download and having a progress in my development. However, the file created is blank. I'm sure this occur as the href of link to download file is: href="./files?3-2.ILinkListener-files-1-download" and the $oLink.href = filehttps://192.168.xx.xxx/backup/files?3-1.ILinkListener-help_link-link. Is there anything I can do to get url and save as file correctly?

Link to comment
Share on other sites

This is a response due to a PM.

With UI Automation code you can generally automate tasks that a user can perform. But it has to be a real user and not just the System account. There are several examples that show that this is not possible. It's possible to save a file downloaded with IE through UIA code. But not with the System account that you want.

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