Example that clicks the "COMPOSE" button in Gmail.
Code: Select all
While ( value <> "COMPOSE" )
value := Pwb.document.getElementsByTagName( "div")[ A_Index - 1].innerText, index := A_Index - 1
Pwb.document.getElementsByTagName( "div")[ index].Click()
Other methods ( same code just moved around, Thanks to TLM )
Code: Select all
While ( Pwb.document.getElementsByTagName( "div")[ A_Index - 1].innerText != "COMPOSE" )
index := A_Index - 1
Pwb.document.getElementsByTagName( "div")[ index].Click()
Code: Select all
While ( subObj := Pwb.document.getElementsByTagName( "div")[ A_Index - 1].innerText != "COMPOSE" )
index := A_Index
subObj.Click()
Explanation
It loops through the document, getting the innerText of each element that matches the 'tag'
getElementsByTagName( "div" )
Saving the value of A_Index ( so it can be used later ).
When the text / innerHTML matches the one you want it will break the while loop.
value <> "COMPOSE"
It then uses the saved A_Index value to operate on the correct element
Pwb.document.getElementsByTagName( "div")[ index].Click()
Working example
Code: Select all
Pwb := ComObjCreate( "InternetExplorer.Application" ) ; Creates the ComObj
Pwb.Navigate("www.AutoHotkey.com") ; Navigates to AutoHotkey.com
Pwb.Visible := True ; Shows the IE app
While ( Pwb.Busy || Pwb.ReadyState != 4 ) ; Waits for the webpage to finish loading
Sleep 10 ; |
value := "" ; Creates the variable ( not needed )
While ( value <> "Community Forum" ) ; Loops through the elements, until its innerText matches.
value := Pwb.document.getElementsByTagName( "a")[ A_Index - 1].innerText, index := A_Index -1 ; Gets the value, and stores the Index
Pwb.document.getElementsByTagName( "a")[ index].Click() ; Clicks on the Community Forum link.