Jump to content
dnnytn

How to Click on Javascript / Dojo TreeNode on Webpage

Recommended Posts

dnnytn

Hi Everyone, due to email system migration, I am trying to automate the email forwarding per account basis on webmail. The action required for each user is:

1. Logging in to webmail for the user

2. Click on the "Options" link

3. On the pop-up box, click on "Mail", then "Forwarding" (Screen shot provided)

4. Followed by keying in the forwarding details. 

I am stuck on step 3. It appears that the links for "Mail" and "Forwarding" are javascript and not real links. I do not have any programming and development experience and just started with AutoIT 2 weeks back just for this specific task. 

The source for the page is here, it looks like the part that i should be focusing on is : 

 

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Strict//EN' 'http://www.w3.org/TR/html4/strict.dtd'>
<html>
<head>
  <meta http-equiv='X-UA-Compatible' content='IE=EmulateIE7'>
  <title>WebMail - Corporate Edition - Options</title>
  
  <link rel='stylesheet' type='text/css' href='/extras/dojo/dojo1.4.3/dojox/grid/resources/Grid.css'>
  <link rel='stylesheet' type='text/css' id='tundraGrid' href='/extras/dojo/dojo1.4.3/dojox/grid/resources/tundraGrid.css'>

  
  <meta http-equiv='X-UA-Compatible' content='IE=EmulateIE7'>
  <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
  <script type='text/javascript'> 
  try{ 
  document.execCommand('BackgroundImageCache', false, true); 
  }catch(e){} 
  </script>   
  
<link rel='stylesheet' type='text/css' href='/extras/dojo/dojo1.4.3/dojo/resources/dojo.css'>
<link rel='stylesheet' type='text/css' id='tundra' href='/extras/dojo/dojo1.4.3/dijit/themes/tundra/tundra.css'>
<style type='text/css'>
  html, body, pre, input,
  .dijitTextBox,
  .dijitComboBox,
  .dijitMenuItem,
  .dijitSpinner,
  .dojoxGrid,
  .dijitTextArea {
     font-family:  'Lucida Grande', Tahoma, Arial, Helvetica, sans-serif !important;
  }
  .miraLoadingImg { background: url('/extras/dojo/dojo1.4.3/dojox/image/resources/images/loading.gif'); }
  .tundra .miraToolbar { background:url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/titleBar.png') repeat-x top left !important; }
  .tundra .miraNoSortHeader:hover { background:url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/tabEnabled.png') repeat-x top left !important; } 
  .tundra .miraNoSortHeader {background:url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/tabEnabled.png') repeat-x top left !important; } 
  .tundra .dojoxGridHeader th {background:#E9E9E9 url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/tabEnabled.png') repeat-x top left !important; border-top:0px !important; }
  
  .soria .miraNoSortHeader:hover{ background:url('/extras/dojo/dojo1.4.3/dijit/themes/soria/images/titleBar.png') repeat-x top left; }
  .soria .miraToolbar { background:#eaeaea url('/extras/dojo/dojo1.4.3/dijit/themes/soria/images/titleBar.png') repeat-x top left; }

  .nihilo .miraNoSortHeader:hover{ background:url('/extras/dojo/dojo1.4.3/dijit/themes/nihilo/images/titleBar.png') repeat-x top left; }
  .nihilo .miraToolbar { background:#eaeaea url('/extras/dojo/dojo1.4.3/dijit/themes/nihilo/images/titleBar.png') repeat-x top left; }
  .nihilo .dojoxGridHeader .dojoxGridCell{background:#E9E9E9 url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/tabEnabled.png') repeat-x top left !important; }
  .nihilo .dijitTitlePaneTitle{background:#E9E9E9 url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/tabEnabled.png') repeat-x top left !important; }                   
  .nihilo .dijitToolbar{background:#E9E9E9 url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/tabEnabled.png') repeat-x top left !important; }
  .nihilo .dojoxGridHeader th{background:#E9E9E9 url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/tabEnabled.png') repeat-x top left !important;
    border-top:0px!important;   
     }
  .dojoxGridMasterHeader {background:#E9E9E9 url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/tabEnabled.png') repeat-x top left !important; }
  .dojoxGridHeader th{background:#E9E9E9 url('/extras/dojo/dojo1.4.3/dijit/themes/soria/images/titleBar.png') repeat-x top left !important;
    border-top:0px!important;   
     }
    
    
  .miraPlus { 
    background-image:url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/plusButton.gif'); 
    background-repeat: no-repeat;
    text-align: center;
    vertical-align: middle;
    width: 16px;
    height: 16px;
  }
  .miraMinus { 
    background-image:url('/extras/dojo/dojo1.4.3/dijit/themes/tundra/images/minusButton.gif'); 
    background-repeat: no-repeat;
    text-align: center;
    vertical-align: middle;
    width: 16px;
    height: 16px;
  }
  .miraClose { 
    background-image:url('/extras/dojo/dojo1.4.3/dojox/image/resources/images/close.png');
    background-repeat: no-repeat;
    text-align: center;
    vertical-align: middle;
    width: 16px;
    height: 16px;
  }
  p font {line-height: 120%;}
  h1 font {line-height: 120%;}
  h2 font {line-height: 120%;}
  h3 font {line-height: 120%;}
  h4 font {line-height: 120%;}
  h5 font {line-height: 120%;}
  h6 font {line-height: 120%;}
</style>

 
<script type='text/javascript' src='/extras/dojo/dojo1.4.3/dojo/aggregate_dojo.js' 
        djConfig='isDebug: false, debugAtAllCosts: false,  parseOnLoad: true, usePlainJson: true, 
        baseUrl: "/extras/dojo/dojo1.4.3/dojo/", 
        locale:"en-us", extraLocale: ["en-us"]'></script> 

<script type='text/javascript' src='/extras/dojo/dojo1.4.3/dojo/ce.js'></script>

  
<style type='text/css'>
.gen_silk_icon {
  background-image: url(/wm/eml/icons/silk_imagemap.png?locale=en_US.ISO_8859-1&ui_ver=4.3.7-GA.5&brand=system&deldom=);
  background-repeat: no-repeat;
  width: 16px;
  height: 16px;
  text-align: center;
  vertical-align: middle;
}

.miraLogo {
  background-image: url(/wm/eml/icons/lhs_banner_logo.gif?locale=en_US.ISO_8859-1&ui_ver=4.3.7-GA.5&brand=system&deldom=);
  background-repeat: no-repeat;
  background-position: center center;
  width: 100%;
  height: 100%;
}

.handle {
  background-image: url(/wm/eml/icons/handle.png?locale=en_US.ISO_8859-1&ui_ver=4.3.7-GA.5&brand=system&deldom=);
  background-repeat: repeat-y;
  background-position: 0px 0px;
}

.genInfoSplitter {
  background-image: url(/wm/eml/icons/info_card_splitter.gif?locale=en_US.ISO_8859-1&ui_ver=4.3.7-GA.5&brand=system&deldom=);
  background-repeat: repeat-x;
  background-position: bottom;
  background-color: transparent;
  height: 4px;
  width: 100%;
  margin: 0px;
  padding: 0px;
}

.mcalFreeBusyGridInvalidRow {
  background-image: url(/wm/eml/icons/calendar_freebusy_invalid.gif?locale=en_US.ISO_8859-1&ui_ver=4.3.7-GA.5&brand=system&deldom=);
  position: absolute;
  border-width: 1px 1px 1px 1px;
  border-style: solid;
  border-color: #dddddd;
  z-index: 3;
  height: 19px;
}
</style>

  <link rel='stylesheet' type='text/css' id='system-default' href='/wm/eml/extras/css/aggregated_css/uui_system-default.css?ui_ver=4.3.7-GA.5&locale=en_US.ISO_8859-1&brand=system&deldom='>
  
  <link rel='SHORTCUT ICON' href='/wm/eml/icons/mirapoint.ico?locale=en_US.ISO_8859-1&ui_ver=4.3.7-GA.5&brand=system&deldom='>
  <script type='text/javascript' src='/wm/eml/eui.js?ui_ver=4.3.7-GA.5&locale=en_US.ISO_8859-1&brand=system&deldom='></script>
  
<script type='text/javascript'>
<!-- 
if (typeof __mainWindow__ != 'undefined' && __mainWindow__.__debug__) __include__('/wm/eml/debug.js'); 
//-->
</script>


<script type='text/javascript'>
<!--
    // dojo widgets, handles, etc.
    var model = null, tree = null, 
    stores = {},
    connects = [],
    lhs_item = null,
    anyone_perm_item = null,
    opt_change_ui_cb = dojo.hitch(eUI, 'opt_change_ui'),
    options_items = [];

    
options_items.push({
    'id'        : 'general',
    'label'     : localevar.get('General'),
    'url'       : null,
    'toplevel'  : true,
    'noselect'  : true
});

    

options_items.push({
    'id'    :   'popt_personal',
    'label' :   localevar.get('Account'),
    'url'   :   '/wm/eml/popt_personal.html',
    'pName' :   'general'
});


options_items.push({
    'id'    :   'changepass',
    'label' :   localevar.get('Change Password'), 
    'url'   :   '/cgi-bin/euadmin.cgi/eup/changepass.html',
    'pName' :   'general'
});


options_items.push({
    'id'    :   'popt_colortheme',
    'label' :   localevar.get('Color Theme'), 
    'url'   :   '/wm/eml/popt_colortheme.html',
    'pName' :   'general'
});


options_items.push({
    'id'    :   'popt_aboutpage',
    'label' :   localevar.get('About'), 
    'url'   :   '/wm/eml/popt_aboutpage.html',
    'pName' :   'general'
});


    
options_items.push({
    'id'        : 'mail',
    'label'     : localevar.get('Mail'),
    'url'       : null,
    'toplevel'  : true,
    'noselect'  : true
});

    

options_items.push({
    'id'    :   'mopt_general',
    'label' :   localevar.get('Settings'), 
    'url'   :   '/wm/eml/mopt_general.html',
    'pName' :   'mail'
});


options_items.push({
    'id'    :   'mopt_composing',
    'label' :   localevar.get('Composing'), 
    'url'   :   '/wm/eml/mopt_composing.html',
    'pName' :   'mail'
});


options_items.push({
    'id'        :   'autoreply',
    'label'     :   localevar.get('Auto-Reply'), 
    'url'       :   '/cgi-bin/euadmin.cgi/eup/autoreply.html',
    'pName'     :   'mail'
});


options_items.push({
    'id'    :   'forward',
    'label' :   localevar.get('Forwarding'), 
    'url'   :   '/cgi-bin/euadmin.cgi/eup/forward.html',
    'pName' :   'mail'
});


options_items.push({
    'id'    :   'mopt_signature',
    'label' :   localevar.get('Signature'), 
    'url'   :   '/wm/eml/mopt_signature.html',
    'pName' :   'mail'
});


options_items.push({
    'id'    :   'getmail',
    'label' :   localevar.get('External Mail'), 
    'url'   :   '/cgi-bin/euadmin.cgi/eup/getmail.html',
    'pName' :   'mail'
});


options_items.push({
    'id'    :   'whitelist',
    'label' :   localevar.get('Allowed Senders'), 
    'url'   :   '/wm/eml/mopt_uce.html?ucetype=wl',
    'pName' :   'mail'
});


options_items.push({
    'id'    :   'blacklist',
    'label' :   localevar.get('Blocked Senders'), 
    'url'   :   '/wm/eml/mopt_uce.html?ucetype=bl',
    'pName' :   'mail'
});


options_items.push({
    'id'    :   'whitelistto',
    'label' :   localevar.get('Allowed Mailing Lists'), 
    'url'   :   '/wm/eml/mopt_uce.html?ucetype=recipwl',
    'pName' :   'mail'
});


options_items.push({
    'id'    :   'contfilt_adv',
    'label' :   localevar.get('Message Filters'), 
    'url'   :   '/cgi-bin/euadmin.cgi/eup/contfilt_adv.html',
    'pName' :   'mail'
});


    
options_items.push({
    'id'    :   'calendar',
    'label' :   localevar.get('Calendar'),
    'url'   :   null,
    'toplevel'  :   true,
    'service'   :   'calendar',
    'noselect'  :   true
});

    

options_items.push({
    'id'    :   'prefs_gen',
    'label' :   localevar.get('Presentation'), 
    'url'   :   '/mc/ecal/prefs_gen.html',
    'pName' :   'calendar'
});


options_items.push({
    'id'    :   'reminders',
    'label' :   localevar.get('Reminders'), 
    'url'   :   '/mc/ecal/reminders.html',
    'pName' :   'calendar'
});


options_items.push({
    'id'        :   'permissions',
    'label'     :   localevar.get('Sharing Controls'), 
    'url'       :   '/mc/ecal/permissions.html',
    'service'   :   'group_calendar',
    'pName'     :   'calendar'
});


options_items.push({
    'id'        :   'prefs_publish',
    'label'     :   localevar.get('Publish'), 
    'url'       :   '/mc/ecal/prefs_publish.html',
    'service'   :   'group_calendar',
    'pName'     :   'calendar'
});


    


options_items.push({
    'id'    :   'downloads',
    'label' :   localevar.get('Downloads'),
    'url'   :   null,
    'noselect'  :   true,
    'toplevel'  :   true
});

options_items.push({
    'id'    :   'download_ConnectR',
    'label' :   localevar.get('ConnectR for Outlook'), 
    'url'   :   '/mc/ecal/download_ConnectR.html',
    'pName' :   'downloads'
});





    dojo.addOnLoad(function(){
        stores.lhs = new dojo.data.ItemFileWriteStore({  data: { identifier:   'id',
                                 label:        'label',
                                 items:        eUI.prepareTree(options_items)
                              }
                              });
                            

        model = new dijit.tree.ForestStoreModel({
                                        store: stores.lhs,
                                        query: {toplevel:true},
                                        rootId: "options_root",
                                        childrenAttrs: ["children"]
                                });

        tree = new mira.Tree({
                                    model:      model,
                                    showRoot:   false,
                                    persist:    true,
                    id:         "options_tree"
                                   },
                                   document.getElementById("options_tree_here"));

        tree.startup();

    if (__mainWindow__.prefsMgr.haveService('group_calendar')) {
        stores.permissions = new mira.DataStore({
                            data:   {   identifier:'id',
                    label:'label',
                    items: []}
                    });
    }

        connects.push(dojo.connect(tree, "onClick", eUI, eUI.options_click));    

    eUI.popupLoaded();
    __mainWindow__.prefsMgr.go(eUI, options_items[1]);
    });

//-->
</script>
</head>
<body class="miraPopup tundra" onunload='eUI.eup_unload();'>
<div class="miraPreloader miraLoadingImg" id="mira_preloader"></div>
<div id ="mira_standby" target="opt_rhs" dojoType="dojox.widget.Standby" color="#eeeeee" zIndex="12000"></div>
<div dojoType="dijit.layout.BorderContainer" design="sidebar" style="height:100%;width:100%; overflow:hidden;" gutters="true">
    <div dojoType="dijit.layout.ContentPane" region="left" style="width:225px;" splitter="true">
    <div class="genTitle" style="width:100%;">Options</div>
    <div id="options_tree_here"></div>
    </div>
    <div dojoType="dijit.layout.ContentPane" id="opt_rhs" region="center" style="" onLoad="eUI.options_rhs_loaded();">
    </div>
</div>
</body>
</html>

It seems like the part i should be focusing on is here:

options_items.push({
    'id'    :   'forward',
    'label' :   localevar.get('Forwarding'), 
    'url'   :   '/cgi-bin/euadmin.cgi/eup/forward.html',
    'pName' :   'mail'
});

After searching the forum and reading the help file, I have attempted at least the following: 

1. _IENavigate - fail as the URL is special for each logged in session

2. _IELinkClickByText - failed as no link is found ( i used _IELinkGetCollection = 0 link found)

3. IETableGetCollection - only found 2 tables and its only for the right hand pane of the page. 

4. IEPropertyGet 'innertext' - no errors, but no clicking actions

5. _IETagNameAllGetCollection - Found Tagname: DIV, ID: dijit__TreeNode_10, innertext: * Forwarding but not able to use these information to get autoit to click.

6. _IEImgGetCollection - Found 41 instances of *blank.gif, tried to randomly click an index of gif, but no visible actions being done. 

 

My code is here, it is heavily commented out by the past attempts, so it must be hard to read, apologies in advance. The trouble begins at line 82. Any help or advice is greatly appreciated.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         Danny

 Script Function:
    Automate Mirapoint Forwarding PER user basis. THis needs to run for each
    user that is migrating

#ce ----------------------------------------------------------------------------
#include <IE.au3>
#include <MsgBoxConstants.au3>
;~ #include <Array.au3>

Global $i = 0

If $i = 7 Then
   MsgBox(0, "Rerun", "Lets try that again. Ensure that values are correctly entered")
EndIf

;~ MsgBox(0, "Notice", "System will now help you to forward your mails. Please key in your account information and do not interrupt the process")
;Get Email Address from user
Global $EmailAddr = "username@olddomain.com"

; Asks the user to enter a password.
Global $Password = "passwordentered"

;Get Forwarding Address from user
Global $FwdAddr = "FIRST.LASTname@newdomain.com"

; Display a progress bar window.
    ProgressOn("Progress Meter", "DO NOT INTERRUPT PROCESS", "0%", @DesktopWidth - 310, 0)

; Update the progress value of the progress bar window
    ProgressSet("25%", "25%")



; Open Webmail using IE
Global $oIE = _IECreate("http://webmail.sg.yusen-logistics.com")

_IELoadWait($oIE)

;click on Continue
_IELinkClickByText($oIE, "Continue to this website (not recommended).")

;fill in the user and password and click login button
Global $FormUser = _IEGetObjByName($oIE, "user")
Global $FormPassword = _IEGetObjByName($oIE, "password")
Global $Formlogin = _IEGetObjByName($oIE, "login")
_IEFormElementSetValue($FormUser, $EmailAddr)
_IEFormElementSetValue($FormPassword, $Password)
_IEAction($Formlogin, "click")
_IELoadWait($oIE)

; Update the progress value of the progress bar window
    ProgressSet("50%", "50%")

;#### Click on the "Options" link found on the first frame on top of the website ( 0 )
$oFrame = _IEFrameGetCollection ($oIE)
Local $iNumFrames = @extended
;~ Local $sTxt = $iNumFrames & " frames found" & @CRLF & @CRLF
;~ Local $oFrame = 0
;~ For $i = 0 To ($iNumFrames - 1)
;~     $oFrame = _IEFrameGetCollection($oIE, $i)
;~     $sTxt &= _IEPropertyGet($oFrame, "innertext") & @CRLF
;~ Next
;~ MsgBox($MB_SYSTEMMODAL, "Frames Info", $sTxt)
Sleep(3000)
_IELinkClickByText($oFrame, "Options");click Options link from frame object from its text
_IELoadWait($oIE)



;attach script to new pop up window
$oIE = _IEAttach("https://webmail.sg.yusen-logistics.com/cgi-bin/euadmin.cgi/eup/", "url")
Sleep(6000)


; Update the progress value of the progress bar window
    ProgressSet("65%", "65%")

;### Try using IEFormGetCollection = 1 form, invalid object type
;~ Local $oForms = _IEFormElementGetCollection($oIE)
;~ Local $iNumForms = @extended
;~ MsgBox($MB_SYSTEMMODAL, "Forms Info", "There are " & $iNumForms & " forms on this page")
;~ Local $oForm
;~ For $i = 0 To $iNumForms - 1
;~     $oForm = _IEFormGetCollection($oIE, $i)
;~     MsgBox($MB_SYSTEMMODAL, "Form Info", $oForm.name)
;~ Next






;### Try using IEImgGetCollection = 41 blank.gifs found
;~ Local $oImgs = _IEImgGetCollection($oIE)
;~ Local $iNumImg = @extended

;~ Local $sTxt = "There are " & $iNumImg & " images on the page" & @CRLF & @CRLF
;~ For $oImg In $oImgs
;~    $sTxt &= $oImg.src & @CRLF



;~ Next
;~ MsgBox($MB_SYSTEMMODAL, "Img Info", $sTxt)
;~ _IEImgClick($oIE, "https://webmail.sg.yusen-logistics.com/extras/dojo/dojo1.4.3/dojo/resources/blank.gif", "src", 10)



;#### Try using TagNameGetCollection using DIV
;~ Local $oTags_coll = _IETagNameGetCollection($oIE, "DIV")
;~    For $oTag_enum in $oTags_coll
;~    if $oTag_enum.innertext = "Forwarding" then
;~       MsgBox($MB_SYSTEMMODAL, "ID", "ID :" & $oTag_enum.id)


;~            _IEAction($oTag_enum, "click")

;~            ExitLoop

;~        EndIf
;~    Next

;~ ;#### Try using IETableGetCollection = 2 tables, only shows the right hand pane
;~ Local $oTable = _IETableGetCollection($oIE)
;~ Local $iNumTables = @extended
;~ MsgBox($MB_SYSTEMMODAL, "Table Info", "There are " & $iNumTables & " tables on the page")
;~ Local $oTable = _IETableGetCollection($oIE, 1)
;~ Local $aTableData = _IETableWriteToArray($oTable)
;~ _ArrayDisplay($aTableData)


;#### Try using IEPropertyGet then action click
;~ If _IEPropertyGet($oIE, "innertext") Then
;~     MsgBox($MB_SYSTEMMODAL, "Status", "Forwarding link found")
;~   If String(_IEPropertyGet($oIE, "innertext")) = "* Forwarding" Then
;~    _IEAction($oIE, "focus")
;~       _IEAction($oIE, "click")
;~ Else
;~     MsgBox($MB_SYSTEMMODAL, "Status", "Forwarding link not found")

;~ EndIf


;#### Send manual keyboard commands

;~ Send("{TAB 3}")
;~ Send("{DOWN 9}")
;~ Send("{ENTER}")

;#### Get all frames = 0 Frames found
;~ Local $oFrames = _IEFrameGetCollection($oIE)
;~ Local $iNumFrames = @extended
;~ Local $sTxt = $iNumFrames & " frames found" & @CRLF & @CRLF
;~ Local $oFrame = 0
;~ For $i = 0 To ($iNumFrames - 1)
;~     $oFrame = _IEFrameGetCollection($oIE, $i)
;~     $sTxt &= _IEPropertyGet($oFrame, "innertext") & @CRLF
;~ Next
;~ MsgBox($MB_SYSTEMMODAL, "Frames Info", $sTxt)

;#### Get all tags and IDs in page. Found ID = dijit_TreeNode_10, innertext: *Forwarding)
;~ Local $oElements = _IETagNameAllGetCollection($oIE)
;~ For $oElement In $oElements
;~     If $oElement.id Then MsgBox($MB_SYSTEMMODAL, "Element Info", "Tagname: " & $oElement.tagname & @CRLF & "id: " & $oElement.id & @CRLF & "innerText: " & $oElement.innerText)
;~ Next

;#### Click by ID = dijit__TreeNode_10 (double underscore)
;~ Local $oForward = _IEGetObjById($oIE, 'forward')
;~ MsgBox($MB_SYSTEMMODAL, "Status", @error)
;~ _IEAction($oForward, "focus");
;~ _IEAction($oForward, "click");
; Get coordinates and dimensions of the dijit__TreeNode_10
;~ Local $iScreenX = _IEPropertyGet($oForward, "screenx")
;~ Local $iScreenY = _IEPropertyGet($oForward, "screeny")
;~ Local $iBrowserX = _IEPropertyGet($oForward, "browserx")
;~ Local $iBrowserY = _IEPropertyGet($oForward, "browserY")
;~ Local $iWidth = _IEPropertyGet($oForward, "width")
;~ Local $iHeight = _IEPropertyGet($oForward, "height")
;~ Local $iMousespeed = 50
;~ MouseMove($iScreenX + $iWidth / 2, $iScreenY + $iHeight / 2, $iMousespeed)



;#### Click by text = *Forwarding and * Forwarding (with space)
;~ _IELinkClickByText($oIE, "*Forwarding")

;#### Get all links in page = 0 links found
;~ $oLinks = _IELinkGetCollection($oIE)
;~ Local $iNumLinks = @extended

;~ Local $sTxt = $iNumLinks & " links found" & @CRLF & @CRLF
;~ For $oLink In $oLinks
;~     $sTxt &= $oLink.href & @CRLF
;~ Next
;~ MsgBox($MB_SYSTEMMODAL, "Link Info", $sTxt)

;#### Click by objectname = forward, * Forward, *Forward
;~ Local $oForward = _IEGetObjByName($oIE, "*Forward")
;~ _IEAction($oForward, "click");click Forward link from frame object from its text

;#### Using IENavigate to the url
;~ _IENavigate($oIE, "https://webmail.sg.yusen-logistics.com/wm/mail/cgi-bin/euadmin.cgi/eup/forward.html")

#cs------------------
;click on Yes radio button and key in forwarding email address
Sleep(1000)
Send("{TAB 4}")
Send("{SPACE}")
Send("{TAB}")
Send($FwdAddr)
Send("+{TAB 3}")
Send("{SPACE}")
Sleep(1500)
Send("{TAB 2}")
Send("{ENTER}")
#ce------------------
;~ ;Click on the "Apply Button"
;~ $oFrame = _IEFrameGetCollection ($oIE, 1)
;~ _IEImgClick($oFrame, "Apply", "alt")
;~ Sleep(2000)
;~ ;Click on Close
;~ ;_IEImgClick($oFrame, "Close", "alt")
;~ _IEQuit($oIE)
$oIE = _IEAttach("WebMail - Corporate Edition")
;~ _IEQuit($oIE)

 

Options_Page.png

Share this post


Link to post
Share on other sites
bikerbrooks
; example of tag and innerhtml <span class="buttonText">start</span>
    $spans = $ie.document.getElementsByTagName('span')
    for $s in $spans
    If $s.innerHTML = "start" Then
        $s.click()
    EndIf
    Next

if to right click view sourcecode on the page find the tag and the innerHTML this will work

i use w3schools for this as they give you examples

Share this post


Link to post
Share on other sites
mLipok

How many "!DOCTYPE" tag you see in your HTML source in your webpage ?

 

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 *
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 API *

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 *

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-09-20

Share this post


Link to post
Share on other sites
dnnytn
On 1/6/2016 at 4:16 AM, mLipok said:

How many "!DOCTYPE" tag you see in your HTML source in your webpage ?

 

hi mLipok, i only see 1 x <!Doctype> tag when i use the View Source function in IE. 

Share this post


Link to post
Share on other sites
dnnytn
On 1/4/2016 at 2:41 AM, bikerbrooks said:
; example of tag and innerhtml <span class="buttonText">start</span>
    $spans = $ie.document.getElementsByTagName('span')
    for $s in $spans
    If $s.innerHTML = "start" Then
        $s.click()
    EndIf
    Next

if to right click view sourcecode on the page find the tag and the innerHTML this will work

i use w3schools for this as they give you examples

hi bikerbrooks, based on the View Source page, i am not able to get any clues on which Tag. 

options_items.push({
    'id'    :   'forward',
    'label' :   localevar.get('Forwarding'), 
    'url'   :   '/cgi-bin/euadmin.cgi/eup/forward.html',
    'pName' :   'mail'
});

 

Share this post


Link to post
Share on other sites
mLipok
On 4.01.2016 at 9:11 AM, dnnytn said:

3a. On the pop-up box,  (???? What a PopUp ??? )
3b. click on "Mail",
3c. then "Forwarding"

......

I am stuck on step 3.  Please be more precisely: What you mean: 3a ? 3b ? 3c ?

btw.
Inpsect "Mail" and give here Outer HTML snippet for this part of "Tree" .


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
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 API *

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 *

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-09-20

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

  • Similar Content

    • Chimp
      By Chimp
      The DOM allows to do anything with elements and their contents, but first we need to reach the corresponding DOM object, get it into a variable, and then we are able to modify it. *
      Well, this little tool (although it is not very nice aesthetically) allows you to get visually a "selector" usable to reference DOM objects.
      Once you have the "selector" of an element you can pass it to the javascript querySelector() function that will return a reference to that element.
      To use this tool you have to:
      1) open the web page you want to inspect into IE browser
      2) run this script (if it find more instances of IE running, it allows you to chose one)
      3) move the mouse over the browser. The "selector" of the element below the pointer is catched automatically while hovering. To copy the selector in the clipboard just right click on the element.
      As you can see, while hovering, the element pointed by the mouse is highlighted with a thin red dotted frame to allow you to better "take aim"
      when the selector is copied to the clipboard a little acoustic signal is emitted as a confirm, then you can paste it in your listing where you need it.
      I hope it can come in handy and save you time when you need to automate a site .... have fun
      #include <IE.au3> #include <GUIConstantsEx.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <Misc.au3> ; for _IsPressed (23 END key) Global $hDLL = DllOpen("user32.dll") ; following global variables are automatically updated by events from the browser ; ------------------------------------------------------------------------------------- Global $g_iMouseX, $g_iMouseY ; coordinates of the mouse while mooving over the browser Global $bCopySelector = False ; becomes True when you right click on wanted element ; ------------------------------------------------------------------------------------- Global $oIE = _Get_IE() ; get IE instance to inspect If IsObj($oIE) Then $hIE = _IEPropertyGet($oIE, "hwnd") WinActivate($hIE) _InspectElements() EndIf DllClose($hDLL) Exit Func _InspectElements() ; it uses the global variable $oIE as source ; --- set IE to interact with AutoIt --- Local $oDocument Do ; wait for document Sleep(250) $oDocument = $oIE.document Until IsObj($oDocument) Local $oWindow = $oDocument.ParentWindow ; create a reference to the javascript eval method ; in the body section of the dovument $oWindow.setTimeout("document.body.JSeval = eval; ", 0) ; attach the $JSeval variable to the javascript eval method Local $JSeval Do $JSeval = Execute('$oIE.Document.body.JSeval') Until IsObj($JSeval) ; --------------------------------------------- ; Inject Javascript functions/elements to $oIE ; --------------------------------------------- ; Get the DOM path of an element (a CSS selector) ; ----------------------------------------------- ; This javascript function returns the CSS selector of the passed element. ; You can then use the returned path to get a reference to the pointed ; element by the QuerySelector() javascript function ; function copied from the following link: ; https://stackoverflow.com/questions/5728558/get-the-dom-path-of-the-clicked-a ; see answer by "Aleksandar Totic" (thanks to him) Local $sJScript = "" & _ " function getDomPath(el) {" & _ " if (!el) {" & _ " return;" & _ " }" & _ " var stack = [];" & _ " var isShadow = false;" & _ " while (el.parentNode != null) {" & _ " var sibCount = 0;" & _ " var sibIndex = 0;" & _ " for ( var i = 0; i < el.parentNode.childNodes.length; i++ ) {" & _ " var sib = el.parentNode.childNodes[i];" & _ " if ( sib.nodeName == el.nodeName ) {" & _ " if ( sib === el ) {" & _ " sibIndex = sibCount;" & _ " }" & _ " sibCount++;" & _ " }" & _ " }" & _ " var nodeName = el.nodeName.toLowerCase();" & _ " if (isShadow) {" & _ " nodeName += ""::shadow"";" & _ " isShadow = false;" & _ " }" & _ " if ( sibCount > 1 ) {" & _ " stack.unshift(nodeName + ':nth-of-type(' + (sibIndex + 1) + ')');" & _ " } else {" & _ " stack.unshift(nodeName);" & _ " }" & _ " el = el.parentNode;" & _ " if (el.nodeType === 11) {" & _ " isShadow = true;" & _ " el = el.host;" & _ " }" & _ " }" & _ " stack.splice(0,1);" & _ " return stack.join(' > ');" & _ " }" ; more infos here: https://www.kirupa.com/html5/finding_elements_dom_using_querySelector.htm ; Inject the above javascript function contained in the $sJScript variable into the document _JS_Inject($oIE, $sJScript) Local $_getDomPath ; a reference to call above function from AutoIt Do Sleep(250) $_getDomPath = $jsEval("getDomPath") Until IsObj($_getDomPath) ; ; ; Inject a DIV in the web page ; ---------------------------- ; it will be used to higligt selected element $sJScript = 'au3_div = document.createElement("div");' & _ 'au3_div.style.position = "fixed"; ' & _ 'au3_div.style.width = " 10px"; ' & _ 'au3_div.style.height = " 10px"; ' & _ 'au3_div.style.top = "0px"; ' & _ 'au3_div.style.left = "0px"; ' & _ 'au3_div.style.background = "rgba(0, 255, 0, 0.4);"; ' & _ 'au3_div.style.color = " white"; ' & _ 'au3_div.style.zIndex = "10000"; ' & _ 'au3_div.style.visibility = "hidden"; ' & _ 'document.body.appendChild(au3_div);' _JS_Inject($oIE, $sJScript) Do Sleep(250) $oMyDIV = $jsEval("au3_div") Until IsObj($oMyDIV) ; ------------------- ; hook some IE events ; ------------------- Local $oEventObjects[2], $oEventsSource $oEventsSource = $oIE.document.documentElement ; element we want catch events from ; https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa769636(v=vs.85) $oEventObjects[0] = ObjEvent($oEventsSource, "_HTMLElementEvents2_", "HTMLElementEvents2") ; https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa768283(v%3dvs.85) $oEventObjects[1] = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2") ; open a GUI where to show some element's properties ; -------------------------------------------------- Local $hGUIMain = GUICreate("Info", 500, 100, -1, -1, -1, $WS_EX_TOPMOST) Local $hProperties = GUICtrlCreateEdit("", 0, 0, 500, 100) GUICtrlSetFont(-1, 9, -1, -1, "Courier New") GUISetState() ;Show GUI ; -------------------------------------------------- ; --------- ; Main loop ; --------- Local $iMouseX, $iMouseY, $oElement, $oNewElement, $sSelector Local $oGotElement, $sElementInfos Local $sSaved_StyleOutline ; Loop until the user exits. While IsObj($oIE) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop ; ---> end EndSwitch If ($g_iMouseX <> $iMouseX) Or ($g_iMouseY <> $iMouseY) Then $iMouseX = $g_iMouseX $iMouseY = $g_iMouseY ; $oElement = $oIE.document.elementFromPoint($iMouseX, $iMouseY) ; <-- this way is slower $oNewElement = $JSeval('document.elementFromPoint(' & $iMouseX & ',' & $iMouseY & ');') If $oNewElement <> $oElement Then If IsObj($oElement) Then $oElement.style.outline = $sSaved_StyleOutline $oElement = $oNewElement ; $bSelfie = False ; $iSelf_Timer = TimerInit() $sSaved_StyleOutline = $oElement.style.outline ; save original element outline style $sSelector = $_getDomPath($oElement) If $sSelector <> "" Then $oGotElement = $JSeval('document.querySelector("' & $sSelector & '");') $oGotElement.style.outline = "1px dashed red" ; mark new pointed element ; https://css-tricks.com/ $sElementInfos = "" & _ "nodeName: " & $oGotElement.nodeName & @CRLF & _ "id: " & $oGotElement.id & @CRLF & _ "---------" & @CRLF & _ $sSelector ControlSetText($hGUIMain, "", $hProperties, $sElementInfos) EndIf EndIf EndIf If $bCopySelector And ($sSelector <> "") Then ; And (TimerDiff($iSelf_Timer) > $bSelfie_Delay) Then ; ToolTip ( $sSelector, Default, Default, "", 1, 1) $oMyDIV.style.left = $oGotElement.getBoundingClientRect().left & "px" $oMyDIV.style.top = $oGotElement.getBoundingClientRect().top & "px" $oMyDIV.style.width = $oGotElement.offsetWidth & "px" $oMyDIV.style.height = $oGotElement.offsetHeight & "px" $oMyDIV.style.visibility = "visible" ; shows the green overlay DIV ClipPut($sSelector) $sElementInfos &= @CRLF & "selector copied to ClipBoard" ControlSetText($hGUIMain, "", $hProperties, $sElementInfos) Beep(2000, 50) $bCopySelector = False Sleep(250) $oMyDIV.style.visibility = "hidden" ; hides the green overlay DIV ; ToolTip('') EndIf If _IsPressed("23", $hDLL) Then ; END key pressed If IsObj($oElement) Then $oElement.style.outline = $sSaved_StyleOutline WinActivate($hGUIMain) ; WinSetState($hGUIMain, "", @SW_SHOW) $aWin = WinGetPos($hGUIMain) MouseMove($aWin[0] + $aWin[2] / 2, $aWin[1] + $aWin[3] / 2, 0) EndIf WEnd ; the end ; ------------------------------------------ For $i = 0 To UBound($oEventObjects) - 1 ; Tell IE we don't want to receive events. $oEventObjects[$i] .Stop $oEventObjects[$i] = 0 Next $oIE = 0 ; Remove IE from memory GUIDelete($hGUIMain) ; Remove GUI ; ------------------------------------------ EndFunc ;==>_InspectElements Func _Get_IE() ; Example 5 from the _IEAttach help ; Create an array of object references to all current browser instances ; The first array element will contain the number of instances found Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIEx While 1 $oIEx = _IEAttach("", "instance", $i) If @error = $_IEStatus_NoMatch Then ExitLoop ReDim $aIE[$i + 1] $aIE[$i] = $oIEx $aIE[0] = $i $i += 1 WEnd If $aIE[0] > 0 Then If $aIE[0] = 1 Then Return $aIE[1] ; only one IE is running, return this then ; ; Create a little list box to choose the IE instance from Local $hChoose_IE = GUICreate("IE Instances", 600, 350) Local $Label1 = GUICtrlCreateLabel($aIE[0] & " running Instances of IE browser found, click the one you want to attach to then click on 'ok'", 5, 5, 590, 20) Local $List1 = GUICtrlCreateList("", 5, 30, 590, 300, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL)) Local $hButton_choosed = GUICtrlCreateButton("OK", 5, 325, 590, 20) For $i = 1 To $aIE[0] GUICtrlSetData($List1, $i & ") " & _IEPropertyGet($aIE[$i], "locationurl")) Next GUISetState(@SW_SHOW) While 1 ; wait for a selection Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hChoose_IE) Return False Case $hButton_choosed $aSelected = _GUICtrlListBox_GetSelItems($List1) If $aSelected[0] Then GUIDelete($hChoose_IE) Return $aIE[$aSelected[1] + 1] Else MsgBox(0, "Info", "Please select an item") EndIf EndSwitch WEnd Else MsgBox(0, 'error', "Sorry" & @CRLF & @CRLF & "no running IE instances found") EndIf EndFunc ;==>_Get_IE ; this function creates a javascript script into the html document ; of the passed $oIE object using the createElement method. Func _JS_Inject($oIE, $sJScript, $bIsUrl = False) ; ; get a reference to the document object Local $objDocument = $oIE.document ; Local $oScript = $objDocument.createElement('script') ; $oScript.type = 'text/javascript' If $bIsUrl Then $oScript.src = $sJScript ; works if $sJScript is a link to a js listing (url) Else ; (https://stackoverflow.com/questions/35213147/difference-between-text-content-vs-inner-text) ; $oScript.innerText = $sJScript $oScript.TextContent = $sJScript ; works if $sJScript contains the listing itself EndIf ; $objDocument.getElementsByTagName('head').item(0).appendChild($oScript) ; $objDocument.getElementsByTagName('head').item(0).removeChild($oScript); ; EndFunc ;==>_JS_Inject ; ------------------------------------------------------------------- ; following function(s) are called by registered $oIE elements events ; ------------------------------------------------------------------- ; ; The function automatically fired by an event ; will receive as parameter an Event Obj. ; This obj has properties related to ; the object that fired the event. ; See following link: ; https://msdn.microsoft.com/en-us/library/aa703876(v=vs.85).aspx ; function called by the mousemove event ; we use this to update 2 global variables: Volatile Func _HTMLElementEvents2_onMousemove($oEvent) $g_iMouseX = $oEvent.clientX $g_iMouseY = $oEvent.clientY EndFunc ;==>_HTMLElementEvents2_onMousemove ; function called by the contextmenu event ; we use this to update 1 global variable ; and we also neutralize this event: Volatile Func _HTMLElementEvents2_onContextmenu($oEvent) $oEvent.cancelBubble = True ; event propagation cancelled $oEvent.returnValue = False ; prevent default behaviour $bCopySelector = True ; when True, selector will be copied to clipboard in main loop EndFunc ;==>_HTMLElementEvents2_onContextmenu ; https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa768280%28v%3dvs.85%29 Func _IEEvent_BeforeNavigate2($oIEpDisp, $sIEURL, $iIEFlags, $sIETargetFrameName, $sIEPostData, $iIEHeaders, $bIECancel) ;ConsoleWrite("Debug: navigate away cancelled." & @CRLF) ; https://stackoverflow.com/questions/6526876/how-to-cancel-or-dispose-current-navigation-at-webbrowser-element $oIE.stop EndFunc ;==>_IEEvent_BeforeNavigate2 Here is a simple example on how a "selector" can be used in AutoIt.
      suppose we want automate the login to the AutoIt site with our username and password.
      I've already prepared a very simple "template" where are missing some important parts without which the script can't work. Missing parts are the references to the elements of the AutoIt web page that we have to manage by our script.
      well, here is where the tool I have just posted here above comes to our help.
      follow this steps:
      1) in IE open the AutoIt site at the forum page (https://www.autoitscript.com/forum/)
      2) run the above tool (select the IE instance and/or bring it to front if needed)
      3) when the script is "ready", move the mouse over the "Existing user? Sign In" string and right click the mouse button. Doing so the "selector" of that element is copied to the clipboard. Now we can paste it in our AutoLogIt.au3 script as value of the $sSignIn variable.
      4) now click on the "Existing user? Sign In"  to open the "Sig In" session from where we will copy selectors of each of the 2 input box Username and Password, in the same way as we have already done in step 3, and paste those selectors to the $sInputUserId and $sInputPasswd variables respectively.
      5) do the same for the "Sign In" Button and paste it's selector to the $sSignInButn variable
      6) of course also fill the $sMyUserId and $sMyPasswd variables with your data.
      That's It. Run the AutoLogIt script and it should Log you on automatically to the forum.
      AutoLogIt.au3
      #include <ie.au3> $sMyUserId = "" ; <-- your userid here $sMyPasswd = "" ; <-- your password here ; set selectors here $sSignIn = "" ; <-- SigIn element selector here $sInputUserId = "" ; <-- UserId input selector here $sInputPasswd = "" ; <-- Password input selector here $sSignInButn = "" ; <-- Sig In button selector here $oIE = _IECreate("https://www.autoitscript.com/forum/") ; here is how to use the QuerySelector javascript function $hDOM_Element = $oIE.document.QuerySelector($sSignIn) ; get the "sign in" link element ; perform a click action on the above element $hDOM_Element.click() ; or _IEAction($hDOM_Element, "click") as well ; fill the username input $hDOM_Element = $oIE.document.QuerySelector($sInputUserId) $hDOM_Element.value = $sMyUserId ; fill the password input $hDOM_Element = $oIE.document.QuerySelector($sInputPasswd) $hDOM_Element.value = $sMyPasswd ; .... or also using the dot notation directly .... $oIE.document.QuerySelector($sSignInButn).click() Sleep(5000) ; this should logout $sMenu = "body > div:nth-of-type(2) > header > div > ul > li:nth-of-type(6) > a:nth-of-type(2)" $oIE.document.QuerySelector($sMenu).click() $sLogOut = "body > ul > li:nth-of-type(9) > a" $oIE.document.QuerySelector($sLogOut).click()  
    • Chimp
      By Chimp
      This is a little experiment that makes use of a "Browser Control" embedded in a GUI in order to be able to use AutoIt, HTML, JavaScript and CSS all together.
      This little toy will only work on systems with IE11.
      The purpose is to drag all the names of the scientists & drop on the right ones. (among scientists it has also infiltrated an intruder). I hope you find it entertaining.
      I've posted it here in the hope to have some suggestions on how to improve it all (I mean the interaction between Autoit Javascript html and css). Thanks
      ; this works on systems with IE11 ; ------------------------------- #include <GUIConstantsEx.au3> #include <array.au3> Global $oIE, $oDocument, $ohJS, $sDroping Global $iCorrect = 0, $iGoal = 11 Example() Exit Func Example() Local $aScientists[12][2] = _ [["Schrodinger", "Schrodinger"],["Planck", "Planck"],["Pauli", "Pauli"],["Einstein", "Einstein"], _ ["Chimp", "Chimp"],["Dirac", "Dirac"],["Heisenberg", "Heisenberg"],["Born", "Born"], _ ["De Broglie", "De_Broglie"],["Bohr", "Bohr"],["Sommerfeld", "Sommerfeld"],["", "empty"]] Local $oIE = ObjCreate("Shell.Explorer.2") ; Create a BrowserControl Local $hGUI = GUICreate("", 660, 600, 30, 30) GUICtrlCreateObj($oIE, 0, 0, 660, 600) ; Place BrowserControl on the GUI GUISetState() ;Show GUI $oIE.navigate('about:blank') ; file:///' & @ScriptDir & '\WhoIsWho.html') While Not String($oIE.readyState) = 'complete' ; wait for about:blank Sleep(100) WEnd ; this waits till the document is ready to be used (portion of code from IE.au3) While Not (String($oIE.readyState) = "complete" Or $oIE.readyState = 4) Sleep(100) WEnd While Not (String($oIE.document.readyState) = "complete" Or $oIE.document.readyState = 4) Sleep(100) WEnd $oIE.document.Write(_GetHTML()) ; inject lising directly to the HTML document: $oIE.document.close() ; close the write stream $oIE.document.execCommand("Refresh") While Not String($oIE.readyState) = 'complete' ; wait for readyState after a refresh Sleep(100) WEnd ; https://msdn.microsoft.com/en-us/library/52f50e9t(v=vs.94).aspx ; $ohJS is a reference to the javascript Global Obj ; ------------------------------------------------- $ohJS = $oIE.document.parentwindow.JSglobal $oDocument = $oIE.document Local $oTable1 = $ohJS.table1 Local $oTable2 = $ohJS.table2 _Randomize($aScientists, $oTable1) ; --- Setup events ------------ ; https://msdn.microsoft.com/en-us/library/hh801967(v=vs.85).aspx Local $aoEventObject[2] $aoEventObject[0] = ObjEvent($oTable1, "IEEvent_", "HTMLTableEvents2") $aoEventObject[1] = ObjEvent($oTable2, "IEEvent_", "HTMLTableEvents2") ; ----------------------------- ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch If $iCorrect = $iGoal Then _Goal() _Randomize($aScientists, $oTable1) $iCorrect = 0 EndIf WEnd ; the end For $i = 0 To UBound($aoEventObject) - 1 $aoEventObject[$i] .stop Next $aoEventObject = 0 ; Kill the Event Object $oIE = 0 ; Remove IE from memory (not really necessary). GUIDelete($hGUI) ; Remove GUI EndFunc ;==>Example ; --- event management zone --- ; following functions are fired by events occurred in the browser control Volatile Func IEEvent_onDragstart($oEvent) ; we save the ID of the dragged obj into the $sDroping variable ; for a later use in the drop function $sDroping = $oEvent.srcElement.ID EndFunc ;==>IEEvent_onDragstart Volatile Func IEEvent_onDragOver($oEvent) $ohJS.event.preventDefault() EndFunc ;==>IEEvent_onDragOver Volatile Func IEEvent_onDrop($oEvent) $ohJS.event.preventDefault() If $sDroping <> "" Then If $oDocument.getElementById($sDroping).innerText <> $oEvent.srcElement.innerText Then If $oEvent.srcElement.ClassName = $oDocument.getElementById($sDroping).ClassName Then $oEvent.srcElement.innerText = $oDocument.getElementById($sDroping).innerText $oDocument.getElementById($sDroping).innerText = "" $oDocument.getElementById($sDroping).draggable = False $oDocument.getElementById($sDroping).setAttribute("style") = "background-color: #80ff80;" $iCorrect += 1 Else For $i = 1 To 3 $oDocument.getElementById($sDroping).setAttribute("style") = "background-color: #ff0000;" Sleep(125) $oDocument.getElementById($sDroping).setAttribute("style") = "background-color: #ffffff;" Sleep(125) Next EndIf EndIf $sDroping = "" EndIf EndFunc ;==>IEEvent_onDrop Func _Randomize(ByRef $aScientists, ByRef $oTable) Local $iRows = ($oTable.rows.length) - 1 Local $iCols = ($oTable.rows.item(0).cells.length) - 1 Local $index _ArrayShuffle($aScientists) For $y = 0 To $iRows For $x = 0 To $iCols $index = ($y * ($iCols + 1)) + $x $oTable.rows.item($y).cells.item($x).innerText = $aScientists[$index][0] ; text $oTable.rows.item($y).cells.item($x).className = $aScientists[$index][1] ; class $oTable.rows.item($y).cells.item($x).draggable = $aScientists[$index][0] <> "" Next Next EndFunc ;==>_Randomize Func _Goal() Local $oTable1 = $ohJS.table1 ; names Local $oTable2 = $ohJS.table2 ; photos Local $iRows = ($oTable1.rows.length) Sleep(250) Local $iCols = 6 ; ($oTable1.rows.item(0).cells.length) Local $aIndex[$iRows * $iCols], $sTemp For $i = 0 To UBound($aIndex) - 1 $aIndex[$i] = $i ; + 1 Next _ArrayShuffle($aIndex) For $i = 0 To UBound($aIndex) - 1 $oTable2.rows.item(Int($aIndex[$i] / $iCols)).cells.item(Mod($aIndex[$i], $iCols)).innerText = "" $oTemp0 = $oTable2.rows $oTemp1 = $oTemp0.item(Int($aIndex[$i] / $iCols)).cells $oTemp2 = $oTemp1.item(Mod($aIndex[$i], $iCols)).getAttribute("style") $oTable2.rows.item(Int($aIndex[$i] / $iCols)).cells.item(Mod($aIndex[$i], $iCols)).setAttribute("style") = "background-color: " & _rndColor() Sleep(100); MsgBox(0,"Debug",$sTemp) $oTable2.rows.item(Int($aIndex[$i] / $iCols)).cells.item(Mod($aIndex[$i], $iCols)).setAttribute("style") = $oTemp2 Next For $x = 1 To 2 For $i = 0 To UBound($aIndex) - 1 $oTable1.rows.item(Int($aIndex[$i] / $iCols)).cells.item(Mod($aIndex[$i], $iCols)).setAttribute("style") = "background-color: " & _rndColor() Sleep(100) $oTable1.rows.item(Int($aIndex[$i] / $iCols)).cells.item(Mod($aIndex[$i], $iCols)).setAttribute("style") = "background-color: #ffffff;" Next Next EndFunc ;==>_Goal Func _rndColor() Return String("#" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & ";") EndFunc ;==>_rndColor Func _GetHTML() Local $sHTML = _ "<!DOCTYPE HTML>" & @CRLF & _ "<html>" & @CRLF & _ "<head>" & @CRLF & _ "<meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />" & @CRLF & _ " <script type=""text/javascript"">" & @CRLF & _ " var JSglobal = (1,eval)(""this"");" & @CRLF & _ " </script>" & @CRLF & _ "</head>" & @CRLF & _ "<body>" & @CRLF & _ "<h2>Who is who?</h2>" & @CRLF & _ "<p>Drag&Drop names on the right scientist</p>" & @CRLF & _ "<img src=""http://oi66.tinypic.com/2q0lue9.jpg""" & @CRLF & _ "height=""394"" width=""640""" & @CRLF & _ "style=""position: absolute; left: 10px; top: 100px;"">" & @CRLF & _ "" & @CRLF & _ "<style>" & @CRLF & _ ".target td {width: 100px; height: 160px; text-align: center; color: white; font-weight: bold; vertical-align: bottom; border: 0px solid grey;}" & @CRLF & _ ".source td {width: 100px; height: 30px; text-align: center; border: 1px solid red;}" & @CRLF & _ "</style>" & @CRLF & _ "" & @CRLF & _ "<table class=""target"" style=""position: absolute; left: 25px; top: 100px;"" id=""table2"">" & @CRLF & _ " <tr><td class=""Schrodinger""></td><td class=""Planck""></td><td class=""Pauli""></td><td class=""Einstein""></td><td class=""Chimp""></td><td class=""Dirac""></td></tr>" & @CRLF & _ " <tr><td class=""Heisenberg""></td><td class=""Born""></td><td class=""De_Broglie""></td><td class=""Bohr""></td><td class=""Sommerfeld""></td><td class=""empty""></td></tr>" & @CRLF & _ "</table>" & @CRLF & _ "" & @CRLF & _ "<table class=""source"" style=""position: absolute; left: 10px; top: 504px;"" id=""table1"">" & @CRLF & _ " <tr><td ID=""td1""></td><td ID=""td2""></td><td ID=""td3""></td><td ID=""td4"" ></td><td ID=""td5"" ></td><td ID=""td6"" ></td></tr>" & @CRLF & _ " <tr><td ID=""td7""></td><td ID=""td8""></td><td ID=""td9""></td><td ID=""td10""></td><td ID=""td11""></td><td ID=""td12""></td></tr>" & @CRLF & _ "</table>" & @CRLF & _ "</body>" & @CRLF & _ "</html>" Return $sHTML EndFunc ;==>_GetHTML  
    • RamaKrishna9
      By RamaKrishna9
      What are the minimum system requirements(like Windows OS version, IE browser version, etc,.) for IE.au3(3.3.14.2) to work properly?
    • Seminko
      By Seminko
      Is there a way to grab non-hardcoded but rather javascript generated data from a webpage?
      Tried a get request as well as _IEBodyReadHTML but both seem to grab the code without the javascript generated data.
      $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "link", False) $oHTTP.Send() $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status Global $DataArray[10][5] If $oStatusCode <> 200 Then Exit MsgBox(1, "Error", "Status Code <> 200") EndIf FileWrite(@ScriptDir & "\output.txt", $oReceived) ; //////// #include <IE.au3> Local $FullLink = "link" Local $oIE = _IECreate($FullLink, 0, 0) _IELoadWait($oIE) Local $sText = _IEBodyReadHTML($oIE) FileWrite(@ScriptDir & "\output.txt", $sText)  
    • MakzNovice
      By MakzNovice
      Hello Experts,
      I am working on modifying table data of a browser currently in IE (soon in FF)
      My sequence of operations:
      1. Activate Browser
      2. Get Browser table
      3. Modify data  in table
      4. Suppress any warning/error message from webpage
      5. Activate the Webpage again 
      6. Send {F11} key sequence twice to achieve some update without Updating form ( {F5})
       
      My problem is at Step 5, as it activates the wrong window ( last used application rather than my browser window)
      My code snippet for it as follows
      $bFoundWindow = False Local $aList = WinList("[REGEXPTITLE:(?i)(.*Internet Explorer.*)]") Local $hWND = 0 For $i = 1 To $aList[0][0] If False = $bFoundWindow And $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 1) Then WinActivate($aList[$i][1]) ; 1. Activate Browser window WinSetState ( $aList[$i][1], "", @SW_MAXIMIZE) $hWND = $aList[$i][1] $objEditIE = _IEAttach ($aList[$i][1], "hwnd") $oTitles = _IETagNameGetCollection($objEditIE, "TITLE") For $oTitle In $oTitles $sTitle = $oTitle.innerText If $sTitle = $searchString Then MsgBox(0,"APPLICATION Found", "Got Edit List Window", 1) $bFoundWindow = True ExitLoop EndIf Next EndIf Next If False = $bFoundWindow Then MsgBox(0,"Error","Please launch Edit window for updating values in Browser prior to script execution",10) Exit EndIf ; MY CODE HERE TO MODIFY TABLE ; 2. Get Browser table ; 3. Modify data  in table ; Check if message from webpage pop-up window exists if so click ok on it Local $nCounter = 0 Local $nMaxCounter = 5 while 1 If WinExists("Message from webpage","") Then ControlClick("Message from webpage","","Button1","primary",1) ;4. Suppress any warning/error message from webpage Else $nCounter = $nCounter + 1 Sleep(100) ;MsgBox(0,"Counter", $nCounter, 1) If $nCounter = $nMaxCounter Then ExitLoop EndIf WEnd ;5. Activate the Webpage again  WinActivate($hWND) ; have already tried WinActivate($aList[$i][1]) but no success ;6. Send {F11} key sequence twice to achieve some update without Updating form ( {F5}) Send("{F11}") WinActivate($hWND) ;WinActivate($aList[$i][1]) Sleep(100) Send("{F11}") Any support will be highly appreciated
×