Jump to content

Need help clicking email's subject link via IE.au3


Recommended Posts

I need help that how do I get IE.au3 to automatically click this unread email's subject text in bold format to open this email message (check the image) and then click the Forward button after that. Then once having IE.au3 naviate Back to previous first page and I need to know how to check that checkbox next to first unread email message and click the combo box to chose Trash then click Go button

Problem is I do not how to go about this and I checked out the forum for some examples using _IETagNameGetCollection but I could not figure out how to incorporate it into the script. Included the page source code for the Inbox page with combo box with Go button and the opened email message page with Forward button.

To simpify these steps to be done:

#1: Click first unread email's subject (not the sender's name) to open the message. Subject text always changes.

#2: Click the Forward button

#3: Navigate the pages back to #1 and then check the checkbox for that first unread message

#4: Click combo box to choose Trash and click Go button

Then there would be only 2 unread message left in bold format but other non-bold format can be ignored. Continue these steps again until all unread email messages are gone.

Please help me out on this.

Combo box would listed in order as:

Inbox

Gmail Inbox

Saved

Trash

Edited by Blackstar
Link to comment
Share on other sites

  • Moderators

I'm sure I could spend 30 minutes and write the code for you, but until I see that you have put forth some effort I doubt you will get any help. You said you couldn't figure out how to incoperate something into your script, post what you had tried and we'll try to help you with it.

Edit: added some info

Edited by big_daddy
Link to comment
Share on other sites

I'm sure I could spend 30 minutes and write the code for you, but until I see that you have put forth some effort I doubt you will get any help. You said you couldn't figure out how to incoperate something into your script, post what you had tried and we'll try to help you with it.

Edit: added some info

Logging in and navigate to Email pages work just fine until when it gets to:

Send("{tab 70}")

Send ("{enter}") ;Open first email message

_IELoadWait($o_IE)

It does not always work because depending on how many email messages in Inbox, if got new more emails...it creates extra pages (see the image with "1, 2, 3, 4, 5, 6, Next" above the first email subject title) and throws off the tab count. So I want to scrap that and wants to know how to just search for unread email's subject (in bold) and click it.

then when it gets to this part:

$o_inputs = _IETagNameGetCollection (_IEDocGetObj ($o_IE), "td")

For $o_input in $o_inputs

if StringLeft($o_input.value,7) = "forward" Then ;Click Forward button

$o_input.click

ExitLoop

EndIf

next

_IELoadWait($o_IE)

It didnt click Forward button for some reason.

then after go back to previous page where unread email subject located at:

_IEAction( $o_IE, "back")

_IEAction( $o_IE, "back") ;go back to the 1# page

How to search for first checkbox for first unread email and mark it and choose the combo box to Trash and click Go button?

Also, how to re-check to see if any more unread email subject exist?

Edited by Blackstar
Link to comment
Share on other sites

  • Moderators

This is as far as I can go with the information I have right now.

CAUTION UNTESTED!!!!

#include <IE.au3>

Dim $sUsername = "myusername"
Dim $sPassword = "mypass"

_IEErrorHandlerRegister ()

$oIE = _IECreate ("https://my.t-mobile.com/login/MyTmobileLogin.aspx", 0, 1, 0)
WinWait("My T-Mobile - Microsoft Internet Explorer")
WinSetState("My T-Mobile - Microsoft Internet Explorer", "", @SW_MAXIMIZE)
_IELoadWait ($oIE)

; Get references to the inputs fields and checkbox
$oUsername = _IEGetObjByName ($oIE, "Login1:txtMSISDN")
$oPassword = _IEGetObjByName ($oIE, "Login1:txtPassword")
$oRemember = _IEGetObjByName ($oIE, "Login1:chkRemember")
; Set the values and uncheck the remember box
_IEFormElementSetValue ($oUsername, $sUsername)
_IEFormElementSetValue ($oPassword, $sPassword)
If $oRemember.checked Then
    $oRemember.checked = False
    $oRemember.fireEvent ("onchange")
EndIf

_IELinkClickByText ($oIE, "LOG IN")
;~ ;_IELoadWait($oIE) ; The previous function does this for you

_IELinkClickByText ($oIE, "Access your Desktop Interface")

_IELinkClickByText ($oIE, "Email")

Do
    $bUnread = _GetUnreadEmail()
Until Not $bUnread

; If we make it here we shouldn't have anymore unread messages

Func _GetUnreadEmail()
    Local $i = 1
    ; Get a collection of all links
    $oLinks = _IETagNameGetCollection ($oIE, "a")
    ; Loop through all links
    For $oLink In $oLinks
        $sClassName = $oLink.className
        ; Only the unread messages have a class of "text-bold"
        If Mod($i, 2) = 0 And $sClassName == "text-bold" Then
            $sURL = $oLink.href
            ; This is how we will find the message to delete
            $sUID = StringMid($sURL, 18, 4)
            ; Open the message for reading
            _IENavigate ($oIE, $oLink.href)
            ; Get a reference to the forward button and click it
            $oForward = _IEGetObjByName ($oIE, "forward")
            $oForward.click
            _IELoadWait($oIE)
            
            ;==== Do your message stuff here====;
            
            ; Get a reference to the selection box and select inbox
            $oSelect = _IEGetObjByName ($oIE, "folder_move_dest1")
            _IEFormElementOptionselect ($oSelect, "Inbox")
            ; Get a reference to the go button and click it
            $oGo = _IEGetObjByName ($oIE, "move1")
            $oGo.click
            _IELoadWait ($oIE)
            ; We should be back at the inbox now so we get all the input tags
            $oInputs = _IETagNameGetCollection ($oIE, "input")
            For $oInput In $oInputs
                ; Check to see that it is a checkbox and matches our saved $sUID
                If $oInput.type == "checkbox" And $oInput.value == $sUID Then
                    If Not $oRemember.checked Then
                        $oRemember.checked = True
                        $oRemember.fireEvent ("onchange")
                    EndIf
                    ; Get a reference to the Discared Button and click it
                    $oDiscard = _IEGetObjByName ($oIE, "delete")
                    $oDiscard.click
                    _IELoadWait ($oIE)
                    Return True
                EndIf
            Next
        EndIf
        $i += 1
    Next
    Return False
EndFunc   ;==>_GetUnreadEmail
Link to comment
Share on other sites

Hey big_daddy,

I know this was untested code and I gave it a spin...the code you made up works nearly perfect! I moved some sections of your code around because I wanted to go back to Inbox pages instead of using the Inbox in combo list and then click Go button. And change the $sUID = StringMid($sURL, 18, 4) to $sUID = StringMid($sURL, 48, 4) (http://mail.sideic.dngr.com/view?f=Inbox&uid=6016&page=1&sortby=date&order=down)

And add another line to:

For $oLink In $oLinks

$sClassName = $oLink.className

; Only the unread messages have a class of "text-bold"

If Mod($i, 2) = 0 And $sClassName == "text-bold" Then

if StringInStr($oLink.href, "uid=") Then

$sURL = $oLink.href

; This is how we will find the message to delete

$sUID = StringMid($sURL, 48, 4)

; Open the message for reading

_IENavigate ($oIE, $oLink.href)

because it keep clicking the #2 pages (where "2, 3, 4, 5, 6 Next" are in text-bold too). Yes I know I posted only the partial html code earlier for you to analyze it.

The only thing that it's not checking the checkbox before moving to trash so I had to make some minor changes like adding the:

$oInputs = _IETagNameGetCollection ($oIE, "input")

For $oInput In $oInputs

; Check to see that it is a checkbox and matches our saved $sUID

If $oInput.type == "checkbox" And $oInput.value == $sUID Then

$oRemember = _IEGetObjByName ($oIE, "marked[]")

If Not $oRemember.checked Then

$oRemember.checked = True

$oRemember.fireEvent ("onchange")

EndIf

; Get a reference to the Discared Button and click it

;$oDiscard = _IEGetObjByName ($oIE, "delete")

;$oDiscard.click

_IELoadWait ($oIE)

Return True

EndIf

Next

Now, I found another problem...if the first 2 email messages already have been read (non-bold text, and not moved to trash or discarded) and they are still in Inbox list while the 3rd email is unread and the script look for this 3rd unread message (in bold) and opened the message like we told it to do. After the script forward the email and then go back to Inbox page and it tried to check the first checkbox instead of 3rd checkbox and it was moved to trash. How do we tell the script that we wanted the 3rd checkbox to be checked and not the first one? I ran another test for first 5 read emails while the 6th is unread and still checks the first checkbox. Hmm?

Blackstar

Thanks!....I will test it when I get home from work and post results.

Edited by Blackstar
Link to comment
Share on other sites

  • Moderators

Hey big_daddy,

I know this was untested code and I gave it a spin...the code you made up works nearly perfect! I moved some sections of your code around because I wanted to go back to Inbox pages instead of using the Inbox in combo list and then click Go button. And change the $sUID = StringMid($sURL, 18, 4) to $sUID = StringMid($sURL, 48, 4) (http://mail.sidekick.dngr.com/view?f=Inbox&uid=6016&page=1&sortby=date&order=down)

I was afraid of that, but I'm glad you caught it.

And add another line to:

For $oLink In $oLinks

$sClassName = $oLink.className

; Only the unread messages have a class of "text-bold"

If Mod($i, 2) = 0 And $sClassName == "text-bold" Then

if StringInStr($oLink.href, "uid=") Then

$sURL = $oLink.href

; This is how we will find the message to delete

$sUID = StringMid($sURL, 48, 4)

; Open the message for reading

_IENavigate ($oIE, $oLink.href)

because it keep clicking the #2 pages (where "2, 3, 4, 5, 6 Next" are in text-bold too). Yes I know I posted only the partial html code earlier for you to analyze it.

Another good catch, but after looking at it again my logic was a little off so try the modified function below.

The only thing that it's not checking the checkbox before moving to trash so I had to make some minor changes like adding the:

$oInputs = _IETagNameGetCollection ($oIE, "input")

For $oInput In $oInputs

; Check to see that it is a checkbox and matches our saved $sUID

If $oInput.type == "checkbox" And $oInput.value == $sUID Then

$oRemember = _IEGetObjByName ($oIE, "marked[]")

If Not $oRemember.checked Then

$oRemember.checked = True

$oRemember.fireEvent ("onchange")

EndIf

; Get a reference to the Discared Button and click it

;$oDiscard = _IEGetObjByName ($oIE, "delete")

;$oDiscard.click

_IELoadWait ($oIE)

Return True

EndIf

Next

This change is causing the problems you described below, I copied and pasted, then forgot to update the variables. Fixed this in the function below.

Now, I found another problem...if the first 2 email messages already have been read (non-bold text, and not moved to trash or discarded) and they are still in Inbox list while the 3rd email is unread and the script look for this 3rd unread message (in bold) and opened the message like we told it to do. After the script forward the email and then go back to Inbox page and it tried to check the first checkbox instead of 3rd checkbox and it was moved to trash. How do we tell the script that we wanted the 3rd checkbox to be checked and not the first one? I ran another test for first 5 read emails while the 6th is unread and still checks the first checkbox. Hmm?

Like I pointed out above, this is being caused by the change you made, instead of looking for the matching "uid", you are just specifing the first checkbox.

Func _GetUnreadEmail()
    Local $i = 1
    ; Get a collection of all links
    $oLinks = _IETagNameGetCollection ($oIE, "a")
    ; Loop through all links
    For $oLink In $oLinks
        $sClassName = $oLink.className
        ; Only the unread messages have a class of "text-bold"
        If StringInStr($oLink.href, "uid=") And $sClassName == "text-bold" Then
            If Mod($i, 2) = 0 Then
                $sURL = $oLink.href
                ; This is how we will find the message to delete
                $sUID = StringMid($sURL, 48, 4)
                ; Open the message for reading
                _IENavigate ($oIE, $oLink.href)
                ; Get a reference to the forward button and click it
                $oForward = _IEGetObjByName ($oIE, "forward")
                $oForward.click
                _IELoadWait ($oIE)
                
                ;==== Do your message stuff here====;
                
                ; Get a reference to the selection box and select inbox
                $oSelect = _IEGetObjByName ($oIE, "folder_move_dest1")
                _IEFormElementOptionselect ($oSelect, "Inbox")
                ; Get a reference to the go button and click it
                $oGo = _IEGetObjByName ($oIE, "move1")
                $oGo.click
                _IELoadWait ($oIE)
                ; We should be back at the inbox now so we get all the input tags
                $oInputs = _IETagNameGetCollection ($oIE, "input")
                For $oInput In $oInputs
                    ; Check to see that it is a checkbox and matches our saved $sUID
                    If $oInput.type == "checkbox" And $oInput.value == $sUID Then
                        If Not $oInput.checked Then
                            $oInput.checked = True
                            $oInput.fireEvent ("onchange")
                        EndIf
                        ; Get a reference to the Discared Button and click it
                        $oDiscard = _IEGetObjByName ($oIE, "delete")
                        $oDiscard.click
                        _IELoadWait ($oIE)
                        Return True
                    EndIf
                Next
            EndIf
            $i += 1
        EndIf
    Next
    Return False
EndFunc   ;==>_GetUnreadEmail
Link to comment
Share on other sites

Thanks for the tip...that worked nicely!

Blackstar

I was afraid of that, but I'm glad you caught it.

Another good catch, but after looking at it again my logic was a little off so try the modified function below.

This change is causing the problems you described below, I copied and pasted, then forgot to update the variables. Fixed this in the function below.

Like I pointed out above, this is being caused by the change you made, instead of looking for the matching "uid", you are just specifing the first checkbox.

Func _GetUnreadEmail()
    Local $i = 1
    ; Get a collection of all links
    $oLinks = _IETagNameGetCollection ($oIE, "a")
    ; Loop through all links
    For $oLink In $oLinks
        $sClassName = $oLink.className
        ; Only the unread messages have a class of "text-bold"
        If StringInStr($oLink.href, "uid=") And $sClassName == "text-bold" Then
            If Mod($i, 2) = 0 Then
                $sURL = $oLink.href
                ; This is how we will find the message to delete
                $sUID = StringMid($sURL, 48, 4)
                ; Open the message for reading
                _IENavigate ($oIE, $oLink.href)
                ; Get a reference to the forward button and click it
                $oForward = _IEGetObjByName ($oIE, "forward")
                $oForward.click
                _IELoadWait ($oIE)
                
                ;==== Do your message stuff here====;
                
                ; Get a reference to the selection box and select inbox
                $oSelect = _IEGetObjByName ($oIE, "folder_move_dest1")
                _IEFormElementOptionselect ($oSelect, "Inbox")
                ; Get a reference to the go button and click it
                $oGo = _IEGetObjByName ($oIE, "move1")
                $oGo.click
                _IELoadWait ($oIE)
                ; We should be back at the inbox now so we get all the input tags
                $oInputs = _IETagNameGetCollection ($oIE, "input")
                For $oInput In $oInputs
                    ; Check to see that it is a checkbox and matches our saved $sUID
                    If $oInput.type == "checkbox" And $oInput.value == $sUID Then
                        If Not $oInput.checked Then
                            $oInput.checked = True
                            $oInput.fireEvent ("onchange")
                        EndIf
                        ; Get a reference to the Discared Button and click it
                        $oDiscard = _IEGetObjByName ($oIE, "delete")
                        $oDiscard.click
                        _IELoadWait ($oIE)
                        Return True
                    EndIf
                Next
            EndIf
            $i += 1
        EndIf
    Next
    Return False
EndFunc   ;==>_GetUnreadEmail
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...