Automating Chrome with AutoHotkey: Getting InnerText, OuterHTML & Values

AutoHotkey Merchandise-White Stress ballBeing able to Automate Chrome has been a long-time goal of mine.  With GeekDude’s Chrome.ahk Class you now can do this.  Read more about his class on the AHK forum here.

If you didn’t see it, also check out my other tutorial on Setting values with Chrome and AutoHotkey.

 

Here is the function I demonstrate in the below video on Automating Chrome with AutoHotkey: Getting InnerText, OuterHTML & Values
Tab := Chrome.GetTab() ;Connect to Active tab

;********************Methd: Class, Tag, Name, ID **** ***********************************
data:=Chm_Get(Tab,Method:=”Name”,Attribute:=”s”,Index:=2)
;~ MsgBox % data.InnerText
DebugWindow(ExploreObj(data),1,1,200,0)

;********************Method: Class, Tag, Name, ID **** ***********************************
;********************Get Property***********************************
Chm_Get(Tab,Method=”Class”,Attribute=”hfeed”,Index=1){
Obj:={}
;***********Class*******************
if (Format(“{:L}”,Method)=”class”){ ;Case-insensitive check to see if method = Class
Obj.OuterHTML:= Tab.Evaluate(“document.getElementsByClassName(‘” Attribute “‘)[” Index-1 “].outerHTML”).Value
Obj.Value:= Tab.Evaluate(“document.getElementsByClassName(‘” Attribute “‘)[” Index-1 “].value”).Value
Obj.InnerText:= Tab.Evaluate(“document.getElementsByClassName(‘” Attribute “‘)[” Index-1 “].innerText”).Value
Obj.TextContent:= Tab.Evaluate(“document.getElementsByClassName(‘” Attribute “‘)[” Index-1 “].textContent”).Value
} ;***********Tag*******************
Else if (Format(“{:L}”,Method)=”tag”){ ;Case-insensitive check to see if method = Tag
Obj.OuterHTML:= Tab.Evaluate(“document.getElementsByTagName(‘” Attribute “‘)[” Index-1 “].outerHTML”).Value
Obj.Value:= Tab.Evaluate(“document.getElementsByTagName(‘” Attribute “‘)[” Index-1 “].value”).Value
Obj.InnerText:= Tab.Evaluate(“document.getElementsByTagName(‘” Attribute “‘)[” Index-1 “].innerText”).Value
Obj.TextContent:= Tab.Evaluate(“document.getElementsByTagName(‘” Attribute “‘)[” Index-1 “].textContent”).Value
} ;************Name******************
Else if (Format(“{:L}”,Method)=”name”){ ;Case-insensitive check to see if method = Name
Obj.OuterHTML:= Tab.Evaluate(“document.getElementsByName(‘” Attribute “‘)[” Index-1 “].outerHTML”).Value
Obj.Value:= Tab.Evaluate(“document.getElementsByName(‘” Attribute “‘)[” Index-1 “].value”).Value
Obj.InnerText:= Tab.Evaluate(“document.getElementsByName(‘” Attribute “‘)[” Index-1 “].innerText”).Value
Obj.TextContent:= Tab.Evaluate(“document.getElementsByName(‘” Attribute “‘)[” Index-1 “].textContent”).Value
} ;***********ID*******************
Else if (Format(“{:L}”,Method)=”id”){ ;Case-insensitive check to see if method = ID
Obj.OuterHTML:= Tab.Evaluate(“document.getElementById(‘” Attribute “‘).outerHTML”).Value
Obj.Value:= Tab.Evaluate(“document.getElementById(‘” Attribute “‘).value”).Value
Obj.InnerText:= Tab.Evaluate(“document.getElementById(‘” Attribute “‘).innerText”).Value
Obj.TextContent:= Tab.Evaluate(“document.getElementById(‘” Attribute “‘).textContent”).Value
} Else{ MsgBox fix Attribute- Valid values are: Name, Class, Tag, ID
}
return obj
}

 

 

 

Video Tutorial Automating Chrome with AutoHotkey: Getting InnerText, OuterHTML & Values

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.