Jump to content
Sign in to follow this  

javascript and _IEGetObjById

Recommended Posts


A search of a web page can retrieve 1 to 20 (or more) links split into 20 per page I can go on to the second page by using:

If $x = 20 Then
Sleep(2000) ;two seconds
$oNext = _IEGetObjById($oIE, "pager1")
_IEAction($oNext, "click")

where $x is the count of links on the previous page but how do I get to the next page given the next page object is in javascript as seen here:

<a id="pager1" href="javascript:__doPostBack('pager1','2')">2</a> -

<a id="pager1" href="javascript:__doPostBack('pager1','3')">3</a> -

<a id="pager1" href="javascript:__doPostBack('pager1','4')">4</a> -

<a id="pager1" href="javascript:__doPostBack('pager1','5')">5</a>

<a id="pager1" href="javascript:__doPostBack('pager1','2')">Next ></a>

is there a way of sending the doPostBack('pager1','3') information? BTW I just thought (I.m not at my own PC) can I get IEGetObjById by index so somthing like that?

Share this post

Link to post
Share on other sites

Looks like this isn't doable within the confines of Autoit - below is what I've ended up with. I'm curious though if the javascript had been given different id like pager1, pager2, pager3... or been given name="pager1" so I could have used index would it have worked? Oh and I know this only works on some PC & IE combinations - I only have the one PC.

#include <IE.au3>
#include <Array.au3>
#include <Date.au3>
Global $getdate[1]
$file = FileOpen(@MyDocumentsDir & "AIT_count.txt", 2)
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file: " & "C:Documents and Settingsjoe.uryMy DocumentsAutoIt_codegetterprocessingAIT_count.txt")
;get working days in date range
$daysearch = HowManyWorkDays("2003/05/21", "2003/05/23") ;2003/07/01
MsgBox(0, "Number of Weekdays", "There are " & $daysearch & " weekdays between the given dates")
For $i = 1 To $daysearch
;open and fill in the search form
$oIE = _IECreate("www.ait.gov.uk/Public/Searchunreported.aspx")
$oForm = _IEGetObjByName($oIE, "Form1")
_IEAction($oForm, "focus")
$oQuery = _IEFormElementGetObjByName($oForm, "txtDate")
_IEFormElementSetValue($oQuery, $getdate[$i] & @CRLF)
_IEFormElementCheckBoxSelect($oForm, 0, "", 1, "byIndex")
$oNext = _IEGetObjById($oIE, "cmdSearch")
_IEAction($oNext, "click")
;grab results into memory
$filewhole = _IEDocReadHTML($oIE)
;get required links for page 1
$oLinks = _IELinkGetCollection($oIE)
$iNumLinks = @extended
For $oLink In $oLinks
If StringInStr($oLink.href, ".doc") Then
;ConsoleWrite($oLink.href & @CRLF)
FileWrite($file, $oLink.href & " " & $getdate[$i] & @CRLF)
;get page 2 if exists (the problem exists here because they've only given an Id (no name)
;and they've used the same Id to every instance of a new page.
If StringRegExp($filewhole, "('pager1','2')", 0) Then
$oNext = _IEGetObjById($oIE, "pager1")
_IEAction($oNext, "click")
;get required links for page 2
$oLinks = _IELinkGetCollection($oIE)
$iNumLinks = @extended
For $oLink In $oLinks
If StringInStr($oLink.href, ".doc") Then
;ConsoleWrite($oLink.href & @CRLF)
FileWrite($file, $oLink.href & " " & $getdate[$i] & @CRLF)
;guess I'll have to go to each date page over 2 long and do it manually so I'll get that information:
If StringRegExp($filewhole, "('pager1','9')", 0) Then
FileWrite($file, $getdate[$i] & " has 9 pages" & @CRLF)
ElseIf StringRegExp($filewhole, "('pager1','8')", 0) Then
FileWrite($file, $getdate[$i] & " has 8 pages" & @CRLF)
ElseIf StringRegExp($filewhole, "('pager1','7')", 0) Then
FileWrite($file, $getdate[$i] & " has 7 pages" & @CRLF)
ElseIf StringRegExp($filewhole, "('pager1','6')", 0) Then
FileWrite($file, $getdate[$i] & " has 6 pages" & @CRLF)
ElseIf StringRegExp($filewhole, "('pager1','5')", 0) Then
FileWrite($file, $getdate[$i] & " has 5 pages" & @CRLF)
ElseIf StringRegExp($filewhole, "('pager1','4')", 0) Then
FileWrite($file, $getdate[$i] & " has 4 pages" & @CRLF)
ElseIf StringRegExp($filewhole, "('pager1','3')", 0) Then
FileWrite($file, $getdate[$i] & " has 3 pages" & @CRLF)

;what a good function this is!
Func HowManyWorkDays($sStartDate, $sEndDate)
Dim $MyDate
Dim $MyTime
$myStartDate = $sStartDate
$myEndDate = $sEndDate
$countWeekDay = 0
$CountDays = _DateDiff("d", $myStartDate, $myEndDate)
For $inc = 0 To $CountDays
$TempDate = _DateAdd('D', $inc, $myStartDate)
_DateTimeSplit($TempDate, $MyDate, $MyTime)
$FileYear = $MyDate[1]
If $MyDate[2] < 10 Then
$FileMonth = "0" & $MyDate[2]
$FileMonth = $MyDate[2]
If $MyDate[3] < 10 Then
$FileDay = "0" & $MyDate[3]
$FileDay = $MyDate[3]
;Returns Day of the Week Range is 1 to 7 where 1=Sunday
$iWeekday = _DateToDayOfWeek($FileYear, $FileMonth, $FileDay)
If $iWeekday > 1 And $iWeekday < 7 Then
If StringLen($FileDay) = 2 Then
_ArrayAdd($getdate, $FileDay & '-' & $FileMonth & '-' & $FileYear)
$countWeekDay = $countWeekDay + 1
Return $countWeekDay
EndFunc ;==>HowManyWorkDays
Edited by Jury

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  

  • Similar Content

    • PINTO1927
      By PINTO1927
      Hello guys,
      I need to bring up a MsgBox when the user clicks a button on the Internet Explorer page.
      This is the button on the HTML page:
      <button id="NOT_READY_BTN-btnEl" type="button" class="x-btn-center" hidefocus="true" disabled="disabled" role="button" autocomplete="off" data-qtip="ENTRA" style="width: 169px; height: 24px;"> <span id="NOT_READY_BTN-btnInnerEl" class="x-btn-inner" style="width: 169px;">ENTRA</span> <span id="NOT_READY_BTN-btnIconEl" class="x-btn-icon " style="background-image:url(img/icons/ENTRA.gif)"></span></button> Thanks
    • Chimp
      By Chimp
      An example on how to inject jQuery into a web page
      It can be useful to manage the page from AutoIt using jQuery.
      Idea from here: http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
      Suggestions and improvements are welcome
      #include <ie.au3> Example() Func Example() Local $oIE = _IECreate("www.google.com") Local $jQuery = _jQuerify($oIE) MsgBox(0, "Version", "jQuery version: " & $jQuery.fn.jquery) MsgBox(0, "Example", "click ok to exit." & @CRLF & "Google logo will fade out by jQuery...") $jQuery('#hplogo').fadeOut(3000) ; jQuery will fade out the google logo EndFunc ;==>Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _jQuerify ; Description ...: ; Syntax ........: _jQuerify(Byref $oIE) ; Parameters ....: $oIE - Object variable of an InternetExplorer.Application. ; Return values .: an object variable pointing to the jQuery library ; Author ........: Chimp ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _jQuerify(ByRef $oIE) Local $jsEval, $jQuery, $otherlib = False ; create a reference to the javascript eval() function $oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0) Do Sleep(250) $jsEval = Execute('$oIE.Document.head.eval') Until IsObj($jsEval) ; if jQuery is not already loaded then load it If $jsEval("typeof jQuery=='undefined'") Then ; check if the '$' (dollar) name is already in use by other library If $jsEval("typeof $=='function'") Then $otherlib = True Local $oScript = $oIE.document.createElement('script'); $oScript.type = 'text/javascript' ; If you want to load jQuery from a disk file use the following statement ; where i.e. jquery-1.9.1.js is the file containing the jQuery source ; (or also use a string variable containing the whole jQuery listing) ;~ $oScript.TextContent = FileRead(@ScriptDir & "\jquery-1.9.1.js") ; <--- from a file ; If you want to download jQuery from the web use this statement $oScript.src = 'https://code.jquery.com/jquery-latest.min.js' ; <--- from an url $oIE.document.getElementsByTagName('head').item(0).appendChild($oScript) Do Sleep(250) Until $jsEval("typeof jQuery == 'function'") EndIf Do Sleep(250) $jQuery = $jsEval("jQuery") Until IsObj($jQuery) If $otherlib Then $jsEval('jQuery.noConflict();') Return $jQuery EndFunc ;==>_jQuerify  
    • XaelloNegative
      By XaelloNegative
      Hi there.
      Im having some kind of a coder block here, 
      <td class="treeview ctl00_CenterContent_objTreeView_2" style="white-space:nowrap;"> <input type="checkbox" name="ctl00_CenterContent_objTreeViewn1CheckBox" id="ctl00_CenterContent_objTreeViewn1CheckBox"> <span class="ctl00_CenterContent_objTreeView_0 treeview ctl00_CenterContent_objTreeView_1" id="ctl00_CenterContent_objTreeViewt1" style="border-style:none;font-size:1em;"> <i class="fa fa-file-code-o fa-fw"> </i> <span data-placement="bottom" data-toggle="tooltip" title="" data-original-title="Tool tip for said part">REFUNDS</span></span></td> this is a code directly from the website im working with. I was thinking of inserting a javascript that would get the "REFUNDS" part. Any ideas on how to do so?
      Any thoughts will be highly appreciated.
    • Patryk
      By Patryk
      Dear Colleagues,
      I have no idea how to refer to style.display in my loop. There is a button like: 
      <input name="ctl00$bodyPlaceholder$btnFecharProcessamento" class="button" id="bodyPlaceholder_btnFecharProcessamento" style="display: none;" onclick="FecharJanelaProcessamento();return false;" type="submit" value="Fechar"> I want it to be clicked as soon as button's style change from style="display: none;" to  style= ="display: inline-block;" 
      This is what I got, but it's not working...
      Func GetButtons() $oButtons = _IEGetObjByName($oForm,"ctl00$bodyPlaceholder$btnFecharProcessamento",-1) $i = 0 While $i <> 1 For $oBtn In $oButtons If _IEFormElementGetValue($oBtn) = "Fechar" And $oBtn.document.style.display = "display: inline-block;" Then $i = 1 _IEAction($oBtn, "focus") _IEAction($oBtn, "click") ExitLoop EndIf Next WEnd EndFunc  
      I will really appreciate if you could help me with these loop!
    • Omnitica
      By Omnitica
      I'm new to the forums! Couldn't find any threads covering this issue. Sorry if I'm wrong.

      I'm having problems changing the text/value of a input box. The particular box doesn't have a name or id, just: class="jq_hotkeys_enabled form-control".
      This class appears multiple times throughout the source, so I don't think It's right to reference that object. 
      See image 1.
      However, I've managed to find a object with the name "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" which contains the value of the input box, and the id for the person in the dropdown/combobox left of it. (with "dummy-1" selected).
      See image 2.
      As you can see the value is 3982,4545     ( name , time )
      But when I try to change the value of it by doing:
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") The box doesn't get its new value. I  can see in the source that it's changed though.
      See image 3.
      However, if I do: 
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") $oIE.document.parentwindow.execScript("theForm.submit()") ; But it needs to reload the page The box gets its new value after the page reloads by the theForm.submit() function. 
      This is a bit unfortunate as I want the changes to happen instantly like when I type in the box with the keyboard... or select in the combobox.
      Maybe someone knows how I can do this? Looking forward to an answer! 
      Thanks in advance.
      Note: Unfortunately I can't provide with the real URL as it is constricted to employees in the company I work for, but let me know If I should provide anything else.


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.