Jump to content

Recommended Posts

Posted

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)

 

Posted
  On 3/16/2018 at 12:31 PM, 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

Expand  

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.

Posted

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 3/16/2018 at 2:26 PM, 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.

 

Expand  

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

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

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

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