Advertisement
StavenCross

Untitled

Jan 5th, 2020
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Include B:\Progs\AutoHotkey_L\AHK Work\WebPage\Chrome\Examples\Chrome.ahk ;GeekDude Class ; https://github.com/G33kDude/Chrome.ahk https://autohotkey.com/boards/viewtopic.php?t=42890 Tab:=Chm_Create_Instance("C:\Users\joe\AppData\Local\Google\Chrome\User Data\Default") ;Create instance using default Profile Chm_Navigate(Tab,"http://the-automator.com") ;Navigate to a URL Chm_Set(Tab,Method:="Class",Attribute:="s",Index:=2,Property:="v",Value:="Just a test") ;~ Chm_Set(Tab,Method:="Name",Attribute:="s",Index:=2,Property:="v",Value:="Just another test") ;~ Chm_Set(Tab,Method:="tag",Attribute:="Input",Index:=1,Property:="v",Value:="Just a test") ;~ Chm_Set(Tab,Method:="ID",Attribute:="cat",Index:=2,Property:="v",Value:="11") ;********************Chrome Set Property******* Propterty= i=innerText v=Value o=outerHTML**************************** Chm_Set(Tab,Method="Class",Attribute="hfeed",Index=1,Property="i",Value=""){ ;***********Class******************* if (Format("{:L}",Method)="class"){ ;Case-insensitive check to see if method = Class if (Format("{:L}",Property)="o") ;If Property="o" then set OuterHTML Tab.Evaluate("document.getElementsByClassName('" Attribute "')[" Index-1 "].outerHTML='" Value "'").Value Else if (Format("{:L}",Property)="v") ;If Property="v" then set Value Tab.Evaluate("document.getElementsByClassName('" Attribute "')[" Index-1 "].value='" Value "'").Value Else if (Format("{:L}",Property)="i") ;If Property="i" then set innerText Tab.Evaluate("document.getElementsByClassName('" Attribute "')[" Index-1 "].innerText='" Value "'").Value } ;***********Tag******************* Else if (Format("{:L}",Method)="tag"){ ;Case-insensitive check to see if method = Tag if (Format("{:L}",Property)="o") ;If Property="o" then set OuterHTML Tab.Evaluate("document.getElementsByTagName('" Attribute "')[" Index-1 "].outerHTML='" Value "'").Value Else if (Format("{:L}",Property)="v") ;If Property="v" then set Value Tab.Evaluate("document.getElementsByTagName('" Attribute "')[" Index-1 "].value='" Value "'").Value Else if (Format("{:L}",Property)="i") ;If Property="i" then set innerText Tab.Evaluate("document.getElementsByTagName('" Attribute "')[" Index-1 "].innerText='" Value "'").Value } ;***********Name******************* Else if (Format("{:L}",Method)="Name"){ ;Case-insensitive check to see if method = Name if (Format("{:L}",Property)="o") ;If Property="o" then set OuterHTML Tab.Evaluate("document.getElementsByName('" Attribute "')[" Index-1 "].outerHTML='" Value "'").Value Else if (Format("{:L}",Property)="v") ;If Property="v" then set Value Tab.Evaluate("document.getElementsByName('" Attribute "')[" Index-1 "].value='" Value "'").Value Else if (Format("{:L}",Property)="i") ;If Property="i" then set innerText Tab.Evaluate("document.getElementsByName('" Attribute "')[" Index-1 "].innerText='" Value "'").Value } ;***********ID******************* Else if (Format("{:L}",Method)="id"){ ;Case-insensitive check to see if method = ID if (Format("{:L}",Property)="o") ;If Property="o" then set OuterHTML Tab.Evaluate("document.getElementById('" Attribute "').outerHTML='" Value "'").Value Else if (Format("{:L}",Property)="v") ;If Property="v" then set Value Tab.Evaluate("document.getElementById('" Attribute "').value='" Value "'").Value Else if (Format("{:L}",Property)="i") ;If Property="i" then set innerText Tab.Evaluate("document.getElementById('" Attribute "').innerText='" Value "'").Value } Else{ MsgBox fix Method- Valid values are: Name, Class, Tag, ID (case of text does not matter) } } ;********************Create instance and use a path to profile*********************************** Chm_Create_Instance(Profile_Path=""){ if !(Profile_Path){ FileCreateDir, ChromeProfile ;Make sure folder exists ChromeInst := new Chrome("ChromeProfile") ;Create a new Chrome Instance }Else{ try ChromeInst := new Chrome(Profile_Path) ;Create for profile lookup prfile by putting this in your url in Chrome chrome://version/ } return Tab := ChromeInst.GetTab() ;Connect to Active tab } ;********************Navigate to page*********************************** ;~ Chm_Navigate(Tab,"http://the-automator.com") Chm_Navigate(Tab,URL){ Tab.Call("Page.navigate", {"url": URL}) ;Navigate to URL Tab.WaitForLoad() ;Wait for page to finish loading }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement