Jump to content
cheesestain

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

Recommended Posts

cheesestain

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)

 

Share this post


Link to post
Share on other sites
JLogan3o13

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


√-1 2^3 ∑ π, and it was delicious!

Share this post


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

Share this post


Link to post
Share on other sites
mLipok

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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
 

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 *

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 * 

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 TaskScheduler

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 *

"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: 2018-10-31

Share this post


Link to post
Share on other sites
mLipok
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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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
 

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 *

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 * 

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 TaskScheduler

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 *

"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: 2018-10-31

Share this post


Link to post
Share on other sites
cheesestain
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?

Share this post


Link to post
Share on other sites
mLipok
Posted (edited)

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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
 

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 *

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 * 

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 TaskScheduler

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 *

"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: 2018-10-31

Share this post


Link to post
Share on other sites
cheesestain

Thanks I'll give it a shot.

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

×