Jump to content

Internet Explorer Automation UDF library


DaleHohm
 Share

Recommended Posts

$o_Inbox IS really made with _IECreate()

Don't know why you'd have trouble... the following works fine for me:
#include <IE.au3>

$oIE = _IECreate()
_IENavigate($oIE, "http://www.google.com")

_IEQuit($oIE)

If _IEGetProperty($oIE, "visible") Then
    ConsoleWrite("Browser Is Active" & @CR)
Else
    ConsoleWrite("Browser Is Gone" & @CR)
EndIf

Exit

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

butta, i'm doing it a bit more difficult. here it comes B)

look at the first WHILE loop and the LAST function named _Inbox()

#include <IE.au3>
#include <GuiConstants.au3>
#Include <Constants.au3>
#include <string.au3>

Global $MasterPass = "groente"
Global $Message = ""
Global $Refresh = 1

Opt("WinTitleMatchMode", 1)
opt("TrayMenuMode",1)
opt("TrayOnEventMode",1)
opt("GuiOnEventMode",1)

_Init()
_check()

while 1
sleep($Timer)
if $refresh = 0 Then
    if not _IEGetProperty($o_Inbox, "visible") Then
        $refresh = 1
    EndIf
EndIf

if $Refresh = 1 Then
_IEAction($o_IE,"refresh")
_IELoadWait($o_IE)
_check()
EndIf
WEnd

Func _Init()
#region MENU
TraySetClick (8)
$trayexit = TrayCreateItem ( "Exit")
TrayItemSetOnEvent(-1,"_exit")
$traysetpass = TrayCreateItem("Options")
TrayItemSetOnEvent(-1,"_options")
$traysetpass = TrayCreateItem("Inbox")
TrayItemSetOnEvent(-1,"_Inbox")
#endregion
#region OPTIONS
Global $GUIOptions = GuiCreate("Options", 392, 316)

GuiCtrlCreateLabel("Username", 10, 10, 90, 20)
GuiCtrlCreateLabel("Password", 10, 40, 90, 20)

Global $InputUser =GuiCtrlCreateInput("", 110, 10, 120, 20)
Global $InputPass = GuiCtrlCreateInput("", 110, 40, 120, 20,0x0020)

$ButtonOK = GuiCtrlCreateButton("OK", 290, 280, 90, 30)
$ButtonCanc = GuiCtrlCreateButton("Cancel", 190, 280, 90, 30)

Global $Radio5 = GuiCtrlCreateRadio("5 Min.", 60, 100, 90, 20)
Global $Radio3 = GuiCtrlCreateRadio("3 Min.", 80, 130, 90, 20)
Global $Radio1 = GuiCtrlCreateRadio("1 Min.", 60, 160, 90, 20)
Global $Radio30 = GuiCtrlCreateRadio("30 Sec.", 80, 190, 90, 20)
Global $Radio0 = GuiCtrlCreateRadio("Don't Check", 60, 220, 90, 20)

GUICtrlSetOnEvent($ButtonCanc,"_CloseCanc")
GUICtrlSetOnEvent($ButtonOK,"_CloseOK")
#endregion

#region INICHECK
if FileExists("Settings.ini") then
    $Dummyuser = IniRead ("Settings.ini","General","User", "error" )
    if $Dummyuser = "error"  Then
        Global $User = ""
    Else 
        Global $User = _StringEncrypt ( 0, $dummyuser, $MasterPass)
    EndIf
    
    $Dummypass = IniRead ("Settings.ini","General","Pass", "error" )
    if $Dummyuser = "error"  Then
        Global $Pass = ""
    Else 
        Global $Pass = _StringEncrypt ( 0, $dummypass, $MasterPass)
    EndIf
    
    $Dummytimer = IniRead ("Settings.ini","General","Timer", "error" )
    if $DummyTimer = "error"  Then
        Global $Timer = 30000
    Else 
        Global $Timer = $dummyTimer
    EndIf
Else
    Global $Pass = ""
    Global $User = ""
    Global $Timer = 30000
    _options()
    while $done = 0
    Wend
EndIf
#endregion
#region LOGIN
TraySetIcon("Shell32.dll",44)
TrayTip ( "Login", "Connection to server, please wait.",1)
Global $o_IE = _IECreate()
;_IEAction($o_IE,"invisible")
_IENavigate($o_IE, "http://intranet.a12.nl")
$o_Frame = _IEFrameGetObjByIndex($o_IE, 4)
$o_form = _IEFormGetObjByIndex($o_Frame, 0)
$o_login = _IEFormElementGetObjByName($o_form, "Gebruiker")
$o_password = _IEFormElementGetObjByName($o_form, "Presenteerwachtwoord")
$o_Button = _IEFormElementGetObjByIndex($o_form, 3)
TrayTip ( "Login", "Connection to server, please wait..",1)
_IEFormElementSetValue($o_login, $User)
_IEFormElementSetValue($o_password, $Pass)
$o_Button.click
TrayTip ( "Login", "Connection to server, please wait...",3)
_IELoadWait($o_Frame)
TraySetIcon("Shell32.dll",176)
TrayTip ( "Login", "Logged on, checking mail",2)
#endregion
EndFunc

Func _check()
$o_Frame = _IEFrameGetObjByIndex($o_IE, 4)
$o_Table =  _IETableGetObjByIndex($o_Frame, 1)
$dummy = _IETableWriteToArray($o_Table)
$reminder = $Message
$Message = "E"&StringTrimRight(StringTrimLeft($dummy[0][0],12),1)
if ($Message == "E") then
    $Message = "Er zijn geen nieuwe berichten"
    ConsoleWrite("Er zijn geen nieuwe berichten"&@CR)
    if not ($reminder == $message) Then
    TrayTip ( "Mail",$Message,3,1)
    endif
Else
    ConsoleWrite($Message&@CR)
    if not ($reminder == $Message) Then
    TrayTip ( "Mail",$Message,3,1)
    endif
EndIf
EndFunc

Func _exit()
    _IEQuit($o_IE)
    Exit
EndFunc

Func _options()
    Global $done = 0
    GuiSetState(@SW_SHOW,$GUIOptions)
    GuiCtrlSetData($InputUser,$User)
    GuiCtrlSetData($InputPass,$Pass)
EndFunc

Func _CloseCanc()
    GuiCtrlSetData($InputUser,$User)
    GuiCtrlSetData($InputPass,$User)
    GuiSetState(@SW_Hide,$GUIOptions)
    Global $done = 1
EndFunc

Func _CloseOK()
    $User = GUICtrlRead($InputUser)
    $Pass = GUICtrlRead($InputPass)
Select
case GUICtrlRead($Radio0) = $GUI_CHECKED
    $Timer = 0
case GUICtrlRead($Radio30) = $GUI_CHECKED
    $Timer = 30000
case GUICtrlRead($Radio1) = $GUI_CHECKED
    $Timer = 60000
case GUICtrlRead($Radio3) = $GUI_CHECKED
    $Timer = (60000 *3)
case GUICtrlRead($Radio5) = $GUI_CHECKED
    $Timer = (60000 * 5)
EndSelect
    IniWrite("Settings.ini","General","Timer",$Timer)
    IniWrite("Settings.ini","General","User",_StringEncrypt ( 1, $User, $MasterPass))
    IniWrite("Settings.ini","General","Pass",_StringEncrypt ( 1, $Pass, $MasterPass))
    GuiSetState(@SW_Hide,$GUIOptions)
    TrayTip ( "Login", "If you changed the password or username, please restart the program.",1)
    Global $done = 1
EndFunc

Func _Inbox()
    $Refresh = 0
    global $o_Inbox = _IECreate()
    _IENavigate($o_Inbox, "https://intranet.a12.nl/IntraMail/inbox.asp")
EndFunc

this should help ya.

thanks for all ur help till now.

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

So did you try the sample code I gave you? If the .visible method doesn't work for you, then I'd suggest the event route -- it is a much more reliable solution.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

So did you try the sample code I gave you? If the .visible method doesn't work for you, then I'd suggest the event route -- it is a much more reliable solution.

Dale

Hi Dale,

should your sample really work?

#include <IE.au3>

$oIE = _IECreate()

_IENavigate($oIE, "http://www.google.com")

_IEQuit($oIE) ; Close the browser and remove the object refernce to it ---> $oIE=0

If _IEGetProperty($oIE, "visible") Then ; here i get an error because the requested action with this object has failed ---> $oIE=0 ---> the object does not exist

ConsoleWrite("Browser Is Active" & @CR)

Else

ConsoleWrite("Browser Is Gone" & @CR)

EndIf

Exit

Sebastian

Edited by bastel123
Link to comment
Share on other sites

_IEQuit($oIE) ; Close the browser and remove the object refernce to it ---> $oIE=0

If _IEGetProperty($oIE, "visible") Then ; here i get an error because the requested action with this object has failed ---> $oIE=0 ---> the object does not exist

Ah, you're right. Sorry about that -- I forgot that I set the object variable to 0 in _IEQuit().

This shows what I indended (thanks for catching this):

#include <IE.au3>

$oIE = _IECreate()
_IENavigate($oIE, "http://www.google.com")

$oIE.quit <-- instead of _IEQuit() which sets object to 0

If _IEGetProperty($oIE, "visible") Then
    ConsoleWrite("Browser Is Active" & @CR)
Else
    ConsoleWrite("Browser Is Gone" & @CR)
EndIf

Exit

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

well i see that it works, but only for a short while, thats why it doesn't work at my program, that only check every 30 sec.

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
Link to comment
Share on other sites

Hello all,

the following code opens a web page, scans all form fields and fills all user/password fields. It works well on pages without frames or pages with FRAMESETs (I walk through all frames recursively).

But for some reason it doesn't work with IFRAME. For example

http://www.unicreditbanca.it/web contains IFRAME (same for hotmail.com ...)

How can I make this work for IFRAMEs as well?

I tried it with IE.au3 and without (see example below), but it doesn't seem to work.

Any ideas?

$Url = "mail.yahoo.com"

$Url = "hotmail.com"

$Url = "http://www.unicreditbanca.it/web/"

$Username = "TEST_U"

$Password = "TEST_P"

$oIE=ObjCreate("InternetExplorer.Application")

With $oIE

.Visible = True

.Navigate($Url)

Do

Sleep(100)

Until (.ReadyState = 4) and (.document.ReadyState = "complete")

EndWith

Sleep (500)

$PasswordFound = 0

if StringInstr($oIE.document.documentelement.outerHTML,"iframe") then MsgBox ( 0, "", "IFRAME found")

RecurseIntoFrames($oIE)

FormFiller ($oIE)

Func RecurseIntoFrames ($o_object)

If IsObj($o_object) = 0 Then Return

For $i = 0 to $o_object.document.parentwindow.frames.length-1

;MsgBox (0,$i,$i)

$oFrame = $o_object.document.parentwindow.frames.item ($i)

FormFiller ($oFrame)

RecurseIntoFrames ($oFrame)

Next

Endfunc

Func FormFiller ($o_object)

$oForms = $o_object.document.forms

For $oForm in $oForms

For $element In $oForm

if $element.tagname="input" Then

Select

Case $element.type = "password"

$element.value = $Password

$element.focus()

$PasswordFound = 1

Case $element.type = "text"

$element.value = $Username

Case Else

EndSelect

EndIf

Next

Next

EndFunc

Link to comment
Share on other sites

I am trying to capture the source code of a page, but if I can not do that yet, the body will be fine. I see in some of the code that is posted that you have to specify the page to grab the source. I am trying to grab the current page on the fly, instead of using $some_page = "http://www.google.com". It could be that I am looking at the wrong example code. Please advise.

Thanks.

Link to comment
Share on other sites

@AutoDave

This is perplexing. I hadn't looked into iFrames much and was surprised to see that they have a very dfferent set of properties than Frames. There is a .contentWindow property that I would expect to have a .document property that sould in turn give us access to everything. Quick initial tests are not working. I'll dig further as I have time.

Dale

I guess I forgot to describe the actual problem ...

The script stops at the following line if a frame is a IFRAME:

$oForms = $o_object.document.forms

Any idea why?

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

@NSearch

Sounds like you are looking for a way to get a COM object reference to a browser instance in the active window. There is no way to do this in AutoIt today -- there are no tools to turn a window handle, for example, into a COM reference. All I can offer you is _IEAttach to get a reference ot an existing instance.

If you are motivated, another board member, temassacro, sent me the following Microsoft Q article reference for a method to do this in C++: http://support.microsoft.com/kb/q249232/ My hope is that this could be turned into a plugin to do this, but I have not had the time to look into it.

Dale

I am trying to capture the source code of a page, but if I can not do that yet, the body will be fine. I see in some of the code that is posted that you have to specify the page to grab the source. I am trying to grab the current page on the fly, instead of using $some_page = "http://www.google.com". It could be that I am looking at the wrong example code. Please advise.

Thanks.

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

@NSearch

there are no tools to turn a window handle, for example, into a COM reference

Yes there is, at least there is with Internet Explorer which I assume the author wants since that is the subject of this thread. Call the Windows API function RegisterWindowMessage() with the argument "WM_HTML_GETOBJECT". The return value should be the identifier for that message. Use that message in a call to the API function SendMessage() and you can get an LRESULT containing the object. Then use the API function ObjectFromLresult() to get an object of the specified type.

Here's some example C++ code I had on hand. Assume hWnd is a valid window which hosts an Internet Explorer object. TEST_IT is a macro which checks the return code from COM methods and returns if the method failed:

LRESULT lRes;
                UINT uiMsg = RegisterWindowMessage("WM_HTML_GETOBJECT");
                SendMessageTimeout(hWnd, uiMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, reinterpret_cast<DWORD*>(&lRes));
                CComQIPtr<IHTMLDocument2> pDoc;

                HRESULT hr = ObjectFromLresult(lRes,IID_IHTMLDocument, 0, reinterpret_cast<void**>(&pDoc));
                TEST_IT(hr, "ObjectFromLresult failed.");

                CComQIPtr<IDispatch> pDisp;
                hr = pDoc->get_Script(&pDisp);
                TEST_IT(hr, "get_Script failed.");

                CComQIPtr<IHTMLWindow2> pWin(pDisp);
                hr = pWin->get_document(&pDoc.p);
                TEST_IT(hr, "get_document failed.");

                CComPtr<IHTMLElement> pElem;
                hr = pDoc->get_body(&pElem);
                TEST_IT(hr, "get_body failed.");

                CComQIPtr<IHTMLElement2> pElem2(pElem);
                long lPos;
                hr = pElem2->get_scrollTop(&lPos);
                TEST_IT(hr, "get_scrollTop failed.");

                std::cout<<"Top: "<<lPos<<std::endl;

The code is translatable to AutoIt although it will require some work such as creating a GUID in the proper format.

Edit: I didn't see the first time that you posted the link to the KB article. Regardless, the code can be done in AutoIt.

Edited by Valik
Link to comment
Share on other sites

Thanks Valik -- I should have know that the phrase "no way to do this in AutoIt" would get your attention. :-)

This is good news. This ability would be very useful and we already that the ability to go the other way (hWnd is a COM property of IWebBrowser2).

It will take some study on my part to implement this (I won't be offended if others want to take a shot at it first).

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Call the Windows API function RegisterWindowMessage() with the argument "WM_HTML_GETOBJECT". The return value should be the identifier for that message. Use that message in a call to the API function SendMessage() and you can get an LRESULT containing the object. Then use the API function ObjectFromLresult() to get an object of the specified type.

Valik-Remind me never to play chess with you! B)
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

I havent been able to get it to work at all.

I have updated to the latest beta of autoit but get this error every time i try one of the sample scripts

C:\Program Files\AutoIt3\Include\IE.au3 (776) : ==> Unable to parse line.: 
If IsObj($o_object.elements) Then 
If IsObj($o_object.e^ ERROR

can anyone help me with this...

Thanks

Link to comment
Share on other sites

Yikes. This is not where you want to start with AutoIt -- you are missing basic concepts. You can look at the examples in reply 3 -- they are all complete (i.e. copy one into a file.au3 and you can run it. IE.au3 is an include file, not a stand-alone script (see #include in the helpfile).

Please spend time in the helpfile and the tutorial you'll find there.

Dale

I havent been able to get it to work at all.

I have updated to the latest beta of autoit but get this error every time i try one of the sample scripts

C:\Program Files\AutoIt3\Include\IE.au3 (776) : ==> Unable to parse line.: 
If IsObj($o_object.elements) Then 
If IsObj($o_object.e^ ERROR

can anyone help me with this...

Thanks

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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