Sign in to follow this  
Followers 0
Jury

javascript and _IEGetObjById

2 posts in this topic

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")
_IELoadWait($oIE)

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



#2 ·  Posted (edited)

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")
Exit
EndIf
;get working days in date range
;yyyy/mm/dd
$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")
Sleep(2000)
$oNext = _IEGetObjById($oIE, "cmdSearch")
_IEAction($oNext, "click")
_IELoadWait($oIE)
;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)
EndIf
Next
Sleep(2000)
;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")
_IELoadWait($oIE)
EndIf
;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)
EndIf
Next
;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)
EndIf
Sleep(2000)
_IEQuit($oIE)
Next
FileClose($file)

;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]
Else
$FileMonth = $MyDate[2]
EndIf
If $MyDate[3] < 10 Then
$FileDay = "0" & $MyDate[3]
Else
$FileDay = $MyDate[3]
EndIf
;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)
EndIf
$countWeekDay = $countWeekDay + 1
EndIf
Next
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  
Followers 0

  • Similar Content

    • milos83
      By milos83
      How can I check if element is focused in Firefox using FF.au3 UDF?
      This is my try:
      I have prepared a function that checks if the object is focused:
       
      _FFCmd('FFau3.isfocused=function isfocused(a){try{return (a === document.activeElement)}catch(e){return}}') $oElm = _FFXPath("//*[@id='someId']") ConsoleWrite(_FFIsFocused($oElm)) Func _FFIsFocused($sElement = "") Local $isFoc = _FFCmd("FFau3.isfocused(" & $sElement & ")") Return $isFoc EndFunc ;==>_FFIsFocused Now, the javascript part is tested and it does return successfully.
      After a lot of try/fails I inserted an alert box in order to display the object being compared.
      Here is what I got
       
      The focused object is: [object XULElement]
      The object that I send for comparing is [object HTMLInputElement]
      Why is that?
       
       
    • SkysLastChance
      By SkysLastChance
      I am not sure on how to grab the innertext I want. Is there a way I can just grab the second line, or is there a better way to do it all together? 
      #include <IE.au3> $oIE = _IEAttach("Form Details") $oDiv = _IEGetObjById($oIE, "Col3") ;Phone MsgBox (0,"Oops",$oDiv.outertext) When I use this code I get

       


       
      html.au3
    • Chimp
      By Chimp
      Hi all.
      I'm playing a bit with the ScriptControl object using as base this example by @genius257.
      here is a very simple try, ... but it fails. what I'm doing wrong?
      Local $oSC = ObjCreate("ScriptControl") $oSC.Language = "JScript" $oSC.ExecuteStatement('alert("I am a javascript alert box!");') MsgBox(0,'AutoIt','Pause') Thanks
    • steveeye
      By steveeye
      Hi, what else can we add in <table> besides <tr> & <td> to make it more interative to the users?
    • Chimp
      By Chimp
      just for further fun Here is a Javascript version of the nice 3D sine wave posted from @UEZ
      This version uses this nice javascript library:(http://visjs.org/graph3d_examples.html).  (All the 'dirty' work is done by the javascript library, so the whole credit goes of course to that library and not to me...) I've simply injected all the html/javascript stuff into a BrowserControl embedded into an AutoIt GUI.
      Have fun
      #include <GUIConstantsEx.au3> Example() Exit Func Example() Local $oIE = ObjCreate("Shell.Explorer.2") ; Create a BrowserControl Local $hGUI = GUICreate("3D Sinus wave animation demo", 660, 650, 30, 30) GUICtrlCreateObj($oIE, 0, 0, 660, 650) ; Place BrowserControl on the GUI GUISetState() ;Show GUI $oIE.navigate('about:blank') 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") ; ----------------------------- ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; the end $oIE = 0 ; Remove IE from memory. GUIDelete($hGUI) ; Remove GUI EndFunc ;==>Example Func _GetHTML() Local $sHTML = _ "<!doctype html>" & @CRLF & _ "<html>" & @CRLF & _ "<head>" & @CRLF & _ " <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />" & @CRLF & _ " <title></title>" & @CRLF & _ "" & @CRLF & _ " <style type=""text/css"">" & @CRLF & _ " body {" & @CRLF & _ " font: 10pt arial;" & @CRLF & _ " }" & @CRLF & _ " </style>" & @CRLF & _ "" & @CRLF & _ " <script type=""text/javascript"" src=""https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.0/vis.min.js""></script>" & @CRLF & _ "" & @CRLF & _ " <script type=""text/javascript"">" & @CRLF & _ " var data = null;" & @CRLF & _ " var graph = null;" & @CRLF & _ " var x0, x1, x2" & @CRLF & _ " function custom(x, y, t) {" & @CRLF & _ " // change this function to change the graph" & @CRLF & _ " x0 = 20 - t/180;" & @CRLF & _ " x1 = (x/x0)*(x/x0) + t/10;" & @CRLF & _ " y1 = (y/x0)*(y/x0) + t/10;" & @CRLF & _ " return Math.sin(Math.sqrt(x1+y1));" & @CRLF & _ " }" & @CRLF & _ " // Called when the Visualization API is loaded." & @CRLF & _ " function drawVisualization() {" & @CRLF & _ " // Create and populate a data table." & @CRLF & _ " data = new vis.DataSet();" & @CRLF & _ " // create some nice looking data with sin/cos" & @CRLF & _ " var steps = 25;" & @CRLF & _ " var axisMax = 314;" & @CRLF & _ " var tMax = 800;" & @CRLF & _ " var axisStep = axisMax / steps;" & @CRLF & _ " for (var t = 300; t <= tMax; t = t + 50) {" & @CRLF & _ " for (var x = -axisMax; x < axisMax; x+=axisStep) {" & @CRLF & _ " for (var y = -axisMax; y < axisMax; y+=axisStep) {" & @CRLF & _ " var value = custom(x, y, t);" & @CRLF & _ " data.add([" & @CRLF & _ " {x:x,y:y,z:value,filter:t,style:value}" & @CRLF & _ " ]);" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " // specify options" & @CRLF & _ " var options = {" & @CRLF & _ " width: '600px'," & @CRLF & _ " height: '600px'," & @CRLF & _ " style: 'surface'," & @CRLF & _ " showPerspective: true," & @CRLF & _ " showGrid: false," & @CRLF & _ " showShadow: false," & @CRLF & _ " // showAnimationControls: false," & @CRLF & _ " keepAspectRatio: true," & @CRLF & _ " verticalRatio: 0.085, // 0.5," & @CRLF & _ " animationInterval: 100, // milliseconds" & @CRLF & _ " animationPreload: true," & @CRLF & _ " animationAutoStart: true," & @CRLF & _ " filterValue: 'time'" & @CRLF & _ " };" & @CRLF & _ "" & @CRLF & _ " // create our graph" & @CRLF & _ " var container = document.getElementById('mygraph');" & @CRLF & _ " graph = new vis.Graph3d(container, data, options);" & @CRLF & _ " }" & @CRLF & _ " </script>" & @CRLF & _ "</head>" & @CRLF & _ "" & @CRLF & _ "<body onload=""drawVisualization();"">" & @CRLF & _ "<div id=""mygraph""></div>" & @CRLF & _ "" & @CRLF & _ "<div id=""info""></div>" & @CRLF & _ "</body>" & @CRLF & _ "</html>" Return $sHTML EndFunc ;==>_GetHTML