Jump to content

How to create condition to handle IE open / save notification bar


Recommended Posts

I have a script that uses IE.au3 to navigate a web site and upload a file.  I need to create a condition to handle the IE open/save notification bar that pops up.

After the upload I'm using _StringBetween to determine if _IEBodyReadText($oIE) contains certain text.  If it does then success, if not it should handle the IE open/save notification bar and cancel report failure.

To get around the IE open/save notification bar I used IUIAutomation to cancel.

 

#include <Constants.au3>
#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <String.au3>
#include <Excel.au3>

Local $oIE = _IECreate("http://website")

_IEAction($oIE, "invisible")
Local $oForm = _IEFormGetObjByName($oIE, "maintenanceForm")
$oQuery = _IEFormElementGetObjByName($oForm, "theFile")
_IEAction($oQuery, "focus")
_IEAction($oQuery, "selectall")
Local $hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "This works")
_IEAction($oIE, "visible")
sleep(1000)
Send ("C:\upload.txt")
sleep(1000)
Send ("{ENTER}")
_IEAction($oQuery, "focus")
Send ("{TAB}")
Send ("{ENTER}")

local $source = _IEBodyReadText($oIE)
local $file = FileOpen("test.txt", $FO_OVERWRITE)
FileWrite($file,$source)
FileClose($file)
local $success   = _StringBetween($source, "File has "," successfully")

#include "UIAWrappers.au3"

If @error then
;~ *** Standard code maintainable ***

AutoItSetOption("MustDeclareVars", 1)
_UIA_setVar("Global.Highlight", False)
_UIA_setVar("oP1","Title:=Management System - Internet Explorer;controltype:=UIA_WindowControlTypeId;class:=IEFrame")   ;Management System - Internet Explorer
_UIA_setVar("oP2","Title:=;controltype:=UIA_PaneControlTypeId;class:=Frame Notification Bar")   ;
_UIA_setVar("oP3","Title:=Notification;controltype:=UIA_ToolBarControlTypeId;class:=DirectUIHWND")  ;Notification

;~ $oUIElement=_UIA_getObjectByFindAll("Cancel.mainwindow", "title:=Cancel;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=Cancel;controltype:=UIA_ButtonControlTypeId;class:=") ;ControlType:=UIA_ButtonControlTypeId;classname:=")

;~ Actions split away from logical/technical definition above can come from configfiles

;~_UIA_Action("oP1","highlight")
_UIA_Action("oP1","setfocus")
;~_UIA_Action("oP2","highlight")
_UIA_Action("oP2","setfocus")
;~_UIA_Action("oP3","highlight")
_UIA_Action("oP3","setfocus")

_UIA_action("oUIElement","highlight")
_UIA_action("oUIElement","click")
MsgBox(4096, 'Needle in a Haystack', "Failed")
ElseIf $success[0] = "uploaded" Then
    MsgBox(4096, 'Needle in a Haystack', $success[0])
EndIf
_IEQuit($oIE)

 

Link to comment
Share on other sites

  • Moderators

If you look at the IUIAutomation thread in the examples forum, or on the Wiki, I believe that is specifically addressed. IIRC it is FAQ 31 on the Wiki

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

1 hour ago, JLogan3o13 said:

If you look at the IUIAutomation thread in the examples forum, or on the Wiki, I believe that is specifically addressed. IIRC it is FAQ 31 on the Wiki

In my tests I'm able to click the cancel button on the notification if it comes up every time.  I'm just not able to build a If @error condition around it when the notification happens.

Link to comment
Share on other sites

it is possible... I solve this in one of my project.

Of course there are some limitation.

I will try to find it.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Do
    .........
Until ControlCommand($sIE_Title, '', '[CLASS:DirectUIHWND; INSTANCE:1]', "IsVisible", "")
.....


ControlSend($sIE_Title, '', '[CLASS:DirectUIHWND; INSTANCE:1]', "!o") ; Alt+o >>> &Open

there was a time when I was wondering whether or not to check the position using:
 

ControlGetPos($sIE_Title,  '', '[CLASS:DirectUIHWND; INSTANCE:1]')

But not implemented yet.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

54 minutes ago, mLipok said:
Do
    .........
Until ControlCommand($sIE_Title, '', '[CLASS:DirectUIHWND; INSTANCE:1]', "IsVisible", "")
.....


ControlSend($sIE_Title, '', '[CLASS:DirectUIHWND; INSTANCE:1]', "!o") ; Alt+o >>> &Open

there was a time when I was wondering whether or not to check the position using:
 

ControlGetPos($sIE_Title,  '', '[CLASS:DirectUIHWND; INSTANCE:1]')

But not implemented yet.

 

I'm not sure I understand.  Where would I use that?  Do I keep the IUIAutomation part of the script that handles the notification?

Link to comment
Share on other sites

Try this:

#include <IE.au3>

_IEErrorNotify(True) ; To write Error/Warning message on Console

_Example()


Func _Example()
    Local $oIE = _IECreate('https://www.autoitscript.com/site/autoit/downloads/', 1)
    _IELoadWait($oIE)
    _IEImgClick($oIE, 'https://www.autoitscript.com/site/wp-content/uploads/2013/02/download_autoit_106x51@2x.png', 'src', 0, 0)


    ConsoleWrite("! 1" & @CRLF)
    Local $sIE_Title = _IEPropertyGet($oIE, 'title')
    ConsoleWrite("! $sIE_Title = " & $sIE_Title & @CRLF)


    While 1
        Sleep(10)
        Do
            Sleep(10)
        Until ControlCommand($sIE_Title, '', '[CLASS:DirectUIHWND; INSTANCE:1]', "IsVisible", "")
        If __DirectUIHWND_Exist($sIE_Title) Then ExitLoop
    WEnd

    ConsoleWrite("! Notification is opened." & @CRLF)

    While 1
        Sleep(1000)

        ; Here may occur problem with windows GUI language localization
        ; ControlSend($sIE_Title, '', '[CLASS:DirectUIHWND; INSTANCE:1]', "!u") ; Alt+u >>> &Uruchom >> &Run
        ControlSend($sIE_Title, '', '[CLASS:DirectUIHWND; INSTANCE:1]', "!a") ; Alt+a >>> &Anuluj >> &Cancel
        If Not __DirectUIHWND_Exist($sIE_Title) Then ExitLoop
    WEnd

EndFunc   ;==>_Example


Func __DirectUIHWND_Exist($sIE_Title)
    Local $aWinGetPos = WinGetPos($sIE_Title, '')
    Local $aControlGetPos = ControlGetPos($sIE_Title, '', '[CLASS:DirectUIHWND; INSTANCE:1]')

    ConsoleWrite($aWinGetPos[3] & @CRLF)
    ConsoleWrite($aControlGetPos[1] & @CRLF)
    ConsoleWrite($aControlGetPos[3] & @CRLF)
    ConsoleWrite(($aWinGetPos[3] - ($aControlGetPos[1] + $aControlGetPos[3])) & @CRLF)
    ConsoleWrite("> " & @CRLF)
    If $aWinGetPos[3] - ($aControlGetPos[1] + $aControlGetPos[3]) < 10 Then
        If ControlCommand($sIE_Title, '', '[CLASS:DirectUIHWND; INSTANCE:1]', "IsVisible", "") Then Return True
    EndIf
    Return False
EndFunc   ;==>__DirectUIHWND_Exist

 

EDIT:
I'm using this just to open PDF downloaded by IE, and this is just 
In a way, it's enough for my needs.
But as I said, this method has its limitations.

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

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