Jump to content
Sign in to follow this  
VeeDub

IE.au3 - working with WorldClient

Recommended Posts

VeeDub

Hi,

I am hoping to write a script to work with WorldClient (the WebMail client for MDaemon )

I am able to logon to WorldClient OK, but once I am logged on I cannot figure out how to select the first message in the InBox.

Hopefully traversing messages in the InBox will be index-based, so once the first message can be accessed, then selecting other messages will be easy. For this reason I would prefer to use IE.au3 to select the first message, but if that cannot be done then I will revert to using Window controls.

I realise it is much easier to give advice if you have access to the WorldClient interface, so I have created a test account.

Here is code that will logon to the test account.

Thanks

VW

AutoItSetOption("TrayIconDebug",1)
    
    $WebMailUsername = "test@zeb.com.au"
    $WebMailPassword = "test1234!@#$"
    
    $oIE = _IECreate ("http://tonydav.ze.net.au:3000")
;   Check @extended return value to see if attach was successful
    If @extended Then
        ConsoleWrite("Attached to Existing Browser" & @CRLF)
    Else
        ConsoleWrite("Created New Browser" & @CRLF)
    EndIf

    If $oIE = 0 Then
;       Error has occurred
        ConsoleWrite("*** Error attempting to load WebMail page ***" & @CRLF)
        Exit
    Else
;       Page loaded OK
;       Enter username and password and login
        $oForms = _IEFormGetCollection ($oIE)
        $iNumForms = @extended
        $oForm = _IEFormGetCollection ($oIE,0)
                
        $oUserName = _IEFormElementGetObjByName($oForm,"User")
        $Status = _IEFormElementSetValue($oUserName,$WebMailUsername)
        If $Status = 0 Then
            ConsoleWrite("*** Username not set ***" & @CRLF)
            ConsoleWrite("*** Error: " & @error & @TAB & @extended & " ***" & @CRLF)
            Exit
        EndIf   
        
        $oPassword = _IEFormElementGetObjByName($oForm,"Password")
        $Status = _IEFormElementSetValue($oPassword,$WebMailPassword)
        If $Status = 0 Then
            ConsoleWrite("*** Password not set ***" & @CRLF)
            ConsoleWrite("*** Error: " & @error & @TAB & @extended & " ***" & @CRLF)
            Exit
        EndIf   
        
        $Status = _IEFormSubmit($oForm)
        If $Status = 0 Then
            ConsoleWrite("*** Login not clicked ***" & @CRLF)
            ConsoleWrite("*** Error: " & @error & @TAB & @extended & " ***" & @CRLF)
            Exit
        EndIf   

        $oFrames = _IEFrameGetCollection ($oIE)
        $iNumFrames = @extended
        ConsoleWrite("Frame Info - there are: " & $iNumFrames & " frames on this page" & @CRLF)
        
        For $i = 0 to $iNumFrames - 1
            $oFrame = _IEFrameGetCollection ($oIE, $i)
            ConsoleWrite("Frame Info: " & $oFrame.name & @CRLF)
            If $i = 0 Then
                ConsoleWrite("Frame Detail: " & _IEPropertyGet ($oFrame, "locationurl") & @CRLF)
            EndIf   
            $oLinks = _IELinkGetCollection($oFrame)
            $iNumLinks = @extended
            ConsoleWrite("Link Info: " & $iNumLinks & " links found" & @CRLF)
            For $oLink In $oLinks
                ConsoleWrite("Link Info: " & $oLink.href & @CRLF)
            Next
        Next
  EndIf

Share this post


Link to post
Share on other sites
DaleHohm

Lots of embedded frames... DebugBar makes it straight forward...

Take a look at this:

#include <IE.au3>

$oIE = _IEAttach("WorldClient")

$oFrame0 = _IEFrameGetObjByName($oIE, "utmostFrame")
$oFrame1 = _IEFrameGetObjByName($oFrame0, "main")
$oFrame2 = _IEFrameGetObjByName($oFrame1, "ListHeader")
$oFrame3 = _IEFrameGetObjByName($oFrame2, "List")

$oMessage1 = _IEGetObjById($oFrame3, "126Email")
$oMessage2 = _IEGetObjById($oFrame3, "127Email")
$oMessage3 = _IEGetObjById($oFrame3, "128Email")

For $i = 0 to 3
    _IEAction($oMessage1, "click")
    Sleep(1000)
    _IEAction($oMessage2, "click")
    Sleep(1000)
    _IEAction($oMessage3, "click")
    Sleep(1000)
Next

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

Share this post


Link to post
Share on other sites
VeeDub

Hi Dale,

I was hoping you would have a look at this.

I do have DebugBar installed, but I still find knowing what to look for and how to use with IE.au3 is a challenge.

I don't think DebugBar was around last time I was working with IE, certainly I was not aware of it. Hopefully this exercise will allow me to master DebugBar sufficiently to become more competent with IE generally and work this stuff out for myself.

One more question on a different topic, if you have a look at the following extract, which is your script appended to the end of my earlier script, you will note that I have included a sleep after the form submit. If I don't do this, your code executes before the page has loaded.

I have needed to insert delays recently, and I find it odd because my understanding of the default IE UDF behaviour is that the script is supposed to wait for the page to load before continuing - and therefore I would have thought that my sleep command would be unnecessary.

Can you shed any light on this?

I am running v3.2.12.0

Thanks for your help, I would have been stuck on this for quite a while otherwise.

VW

$Status = _IEFormSubmit($oForm)
        If $Status = 0 Then
            ConsoleWrite("*** Login not clicked ***" & @CRLF)
            ConsoleWrite("*** Error: " & @error & @TAB & @extended & " ***" & @CRLF)
            Exit
        EndIf   

        Sleep(15000)

        $oFrame0 = _IEFrameGetObjByName($oIE, "utmostFrame")
        $oFrame1 = _IEFrameGetObjByName($oFrame0, "main")
        $oFrame2 = _IEFrameGetObjByName($oFrame1, "ListHeader")
        $oFrame3 = _IEFrameGetObjByName($oFrame2, "List")

        $oMessage1 = _IEGetObjById($oFrame3, "126Email")
        $oMessage2 = _IEGetObjById($oFrame3, "127Email")
        $oMessage3 = _IEGetObjById($oFrame3, "128Email")

        For $i = 0 to 3
            _IEAction($oMessage1, "click")
            Sleep(1000)
            _IEAction($oMessage2, "click")
            Sleep(1000)
            _IEAction($oMessage3, "click")
            Sleep(1000)
        Next

Share this post


Link to post
Share on other sites
VeeDub

Take a look at _IELoadWait. That will allow you to get rid of the sleep commands, and make your script more stable.

@Volly

I tried using _IELoadWait instead of Sleep with the default delay (5 mins) and the script did not wait for anything like 5 minutes.

After looking at the remarks in the helpfile, apparently certain sites that make use of frames (like WorldClient) can unfortunately prevent _IELoadWait from guaranteeing that a page is fully loaded.

So it seems that I will probably have to develop my own logic (not sure what that will be yet) to verify that the page has fully loaded before continuing.

I was planning on using a WebMail client so I could avoid having to deal with POP3 and IMAP complexity. But now it looks like I am going to have a few IE challenges to deal with instead.

Share this post


Link to post
Share on other sites
DaleHohm

@Volly

I tried using _IELoadWait instead of Sleep with the default delay (5 mins) and the script did not wait for anything like 5 minutes.

After looking at the remarks in the helpfile, apparently certain sites that make use of frames (like WorldClient) can unfortunately prevent _IELoadWait from guaranteeing that a page is fully loaded.

So it seems that I will probably have to develop my own logic (not sure what that will be yet) to verify that the page has fully loaded before continuing.

I was planning on using a WebMail client so I could avoid having to deal with POP3 and IMAP complexity. But now it looks like I am going to have a few IE challenges to deal with instead.

Your analysis is most likely correct, but _IELoadWait is still the probable answer.

First, _IEFormSubmit has a wait built in, but alas, it seldom does the right thing as it checks the ready status of the form and the document it is in. After a form submission, the form and the document are often discarded and replaced by a new document. So, start by including the parameter telling the _IEFormSubmit NOT to wait.

Next, _IELoadWait checks the staus of only the main document (in the object you pass). It can however also be used by passing in a frame object. Someone wrote and submitted an _IELoadWait for frames and submitted it to the Snippet database (see me sig) and it will likely do the trick for you. It loops through embedded frames recursively and waits for each to complete before returning. Add this after your _IEFormSubmit.

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

Share this post


Link to post
Share on other sites
VeeDub

@Dale,

I have spent sometime looking at the site with DebugBar and comparing with your script and I can see the values that are used to select the individual messages.

However I don't find DebugBar particularly helpful in understanding the hierarchy of the frames. I am using the DOM target and then clicking on various entries until I find one that has information that seems relevant. I am thinking that using _IEFrameGetCollection and reporting a list of the frames available at each "level" may be easier method to understand the site layout, at least for a newbie.

I can see in DebugBar there are at least two types of message classification

DIV class="MessageContainer unreadMsgs"

DIV class=MessageContainer

Clearly there must be a way that to select all the messages for each category and loop through them, but I need help with how to write the selection criteria. Perhaps I need to define two collection objects, but I can't see how to do that.

Also if I want to display all the fields available for a specific message. For instance in your example where you create the reference to a message

$oMessage1 = _IEGetObjById($oFrame3, "126Email")

can this be done using _IETagNameAllGetCollection?

Thanks

VW

Share this post


Link to post
Share on other sites
DaleHohm

I'm afraid I'm not following your questions.

You cannot get a collection based on classname (DOM does not give you an option to do this), but you can loop through the elements:

$oDivs = _IETagnameGetCollection($o_object, "DIV")
For $oDiv in $oDivs
    ConsoleWrite($oDiv.classname & @CR)
Next

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

Share this post


Link to post
Share on other sites
VeeDub

Dale,

Eventually when I figure out what I am doing I am going to have a loop that runs periodically, perhaps every 5 minutes.

That loop will do something like the following:

- click on "Get Mail" to update the message list for any new e-mail

- identify un-read e-mail

- process each un-read message, take action if necessary

- click on each un-read e-mail message to make it "read" so that those messages will be ignored on the next pass

- wait

So one of things that I need to be able to do is identify Unread messages. The following code works in that respect.

For $oDiv in $oDivs
    If $oDiv.classname = "MessageContainer unreadMsgs" Then
        ConsoleWrite("Unread Message: " & $oDiv.innertext & @CRLF)
    Else
        ConsoleWrite("Read Message: " & $oDiv.classname & " - " & $oDiv.innertext & @CRLF)
    EndIf
NextoÝ÷ Ø­!Ú'ßÛpj{m¢·­®'¯y«­¢+ØÀÌØí½¥Ø¹¥¹¹ÉÑáÐoÝ÷ Ù«-ç(ק¶+'¢Ùjx§û¥Â§jëh×6$oDiv.classname = "MessageContainer unreadMsgs"

VW

Share this post


Link to post
Share on other sites
DaleHohm

There is no facility in the DOM to create a collection by classname. You can create a collection based on Tagname or all Tagname's (TagnameAll) and then loop through the items and check the attributes of the elements (like classname). You may want to consider placing matching element references in an AutoIt array.

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

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
Sign in to follow this  

×