[SOLVED] find table information on IE (HTML DOM?)

Get help with using AutoHotkey and its commands and hotkeys
dan86
Posts: 10
Joined: 09 Nov 2014, 23:53
Facebook: dan.fischer86

[SOLVED] find table information on IE (HTML DOM?)

02 Dec 2014, 13:06

Is there a way to check each time I open a page how many rows in a table there are?

I understand that the HTML DOM has all the information, I just can't find the syntax for accessing and returning the information about how many rows there are in a table on the site, because it changes depending on what dates I enter when I access it.

I want to use that value to loop different parts of my script for different amounts of time based on that value. (table might be 4 line one time, and 50 lines another time)

My Script so far:
(works, but no way to change the amount of loops based from table created with dates input)

Code: Select all

SetKeyDelay, 100

Loginname := "LoginName"
Password := "************"
Client := "MyCompany"
BeginDate := "20/12/2014" ;must be dd:mm:yyyy format
EndDate := "30/12/2014" ;must be dd:mm:yyyy format
Department := "Accounting"
EarningsCode := "STANDBY"
InTime := "0630am"
OutTime := "0630pm"

URL := "https://ezlmappdc2f.adp.com/ezLaborManagerNet/Login/Login.aspx?cID=112868&lng=en-US"

WB := ComObjCreate("InternetExplorer.Application")
WB.Visible := True
WB.Navigate(URL)
While WB.readyState != 4 || WB.document.readyState != "complete" || WB.busy ; wait for page to load
	Sleep, 10
WB.document.getElementById("txtClientName").value := Client
WB.document.getElementsByTagName("TD")[30].Click()	
While WB.readyState != 4 || WB.document.readyState != "complete" || WB.busy ; wait for page to load
	Sleep, 10	
WB.document.getElementById("txtUserID").value := Loginname
WB.document.getElementById("txtPassword").value := Password
WB.document.getElementsByTagName("SPAN")[15].Click()
While WB.readyState != 4 || WB.document.readyState != "complete" || WB.busy ; wait for page to load
	Sleep, 10
WB.document.getElementsByTagName("A")[7].Click()
While WB.readyState != 4 || WB.document.readyState != "complete" || WB.busy ; wait for page to load
	Sleep, 10
WB.document.getElementsByTagName("A")[12].Click()
While WB.readyState != 4 || WB.document.readyState != "complete" || WB.busy ; wait for page to load
	Sleep, 10
WB.document.getElementById("BeginDate").value := BeginDate
WB.document.getElementById("EndDate").value := EndDate
WB.document.getElementsByTagName("TD")[19].Click()	
While WB.readyState != 4 || WB.document.readyState != "complete" || WB.busy ; wait for page to load
	Sleep, 10

; ---------------------- START DEPARTMENT CODES -------------------------------------
loop 13 {
	num := A_Index - 1 ;Shifts numbers based on Loop
	WB.document.getElementById("13_" . num).focus()
	WB.document.getElementById("z_13_" . num).value := Department
}

; ---------------------- START EARNINGS CODES -------------------------------------
loop 6 {
	num := (A_Index * 2) + 1 ; Odd numbers
	WB.document.getElementById("31_" . num).focus()
	WB.document.getElementById("z_31_" . num).value := EarningsCode
}

; ---------------------- START IN TIMES -------------------------------------
loop 12 {
	num := A_Index - 1 ; Shifts numbers based on Loop
	time := 1
	WB.document.getElementById("INTIMEtm_" . num).focus()
	Sleep 1
		if Mod(A_Index, 2) = 0
		Send 0630am
		Else
		Send 0630pm
}

; ---------------------- START OUT TIMES -------------------------------------
loop 12 {
	num := A_Index - 1 ;Shifts numbers based on Loop
	WB.document.getElementById("OUTTIMEtm_" . num).focus()
	Sleep 1
		if Mod(A_Index, 2) = 0
		Send 0630pm
		Else
		Send 0630am
}
Last edited by dan86 on 03 Dec 2014, 15:28, edited 1 time in total.
User avatar
Blackholyman
Posts: 1292
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: find table information on IE (HTML DOM?)

02 Dec 2014, 13:32

Code: Select all

count := wb.document.getElementById("myTable").rows.length

Loop %count%
{
    ; code here
}
You Can also use the table element and loop over its cell elements with a for-loop loop
Last edited by Blackholyman on 03 Dec 2014, 14:44, edited 1 time in total.
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: find table information on IE (HTML DOM?)

03 Dec 2014, 12:03

Blackholyman wrote:You Can also use the table element and loop over its cell elements with a for-loop
Could you provide an example?
dan86
Posts: 10
Joined: 09 Nov 2014, 23:53
Facebook: dan.fischer86

Re: find table information on IE (HTML DOM?)

03 Dec 2014, 14:19

That worked perfectly!

Code: Select all

count := wb.document.getElementById("myTable").rows.length

Loop %count%
{
    ; code here
}
I had to adjust, because the table has a header and footer rows, so a simple -2 fixed that problem after a few minutes of frustration!
User avatar
Blackholyman
Posts: 1292
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: find table information on IE (HTML DOM?)

03 Dec 2014, 14:43

jethrow wrote:
Blackholyman wrote:You Can also use the table element and loop over its cell elements with a for-loop
Could you provide an example?
No! Sorry thats my bad ( comes from seeing 'for' used in javascript examples )


@Dan86

happy it worked out :)
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:

Return to “Ask For Help”

Who is online

Users browsing this forum: RubbeH and 37 guests