neXt wrote:
It is definitely useful, but i would appreciate an example per function.
btw, where is the list of all available functions?
in the front page i will poste here again but will not ever update this copy of the functions
Code:
;~ ******************************************************************************************
;~ ******************************************************************************************
;~ IE 7 functions
;~ ******************************************************************************************
;~ ******************************************************************************************
;~ function list
;~ IE7_Get(title,url="http") gets iwebrowser interface pointer and returns automation dhtml window obj ie parentWindow used itn the below functions
;~ IE7_Navigate(parentWindow,url) Navigate and wait for page Load to complete in same frame
;~ IE7_ExecuteJS(parentWindow, JS_to_Inject, VarNames_to_Return="") Full insertion of javascript or execution or retrieval of new or existing fucntions or variables
;~ IE7_readyState(parentWindow) wait for page Load to complete
;~ IE7_Quit(parentWindow) Closes Window
;~ IE7_New(url) Loads a new window even if one does not currently exist and wait for page Load to complete in same frame
;~ IE7_Click_Text(parentWindow,innerHTML)Clicks a link byt text in the inner html of the a tag and wait for page Load to complete in same frame
;~ IE7_Click_Element(parentWindow,ID1=0) ; clicks first element it finds to match returns error if not found will also trigger readystate
;~ IE7_Button_click(parentWindow,value)Click a button based on the text of the button and wait for page Load to complete in same frame
;~ IE7_Get_DOM(parentWindow,ID1)retreive a dom object by index of all collection id or name attribute
;~ IE7_Set_DOM(parentWindow,ID1,val="innerHTML") set a dom object by index of all collection id or name attribute
;~ ******************************************************************************************
;~ ******************************************************************************************
IE7_Get(title,url="http")
{
;~ title is required and is not case sensitive
;~ url is optional and since . exists in all url schemas it will allow un entered url to default to first found
;~ loop thru open windows for a match
Loop, % COM_Invoke(psw := COM_Invoke(psh:=COM_CreateObject("Shell.Application"), "Windows"), "Count")
{
If ( InStr(LocationName:=COM_Invoke(pwb:=COM_Invoke(psw, "Item", A_Index-1), "LocationName"),title,0)) && (InStr(taburl:=COM_Invoke(pwb, "LocationURL"),url,0) )
{
parentWindow:=COM_Invoke(Document:=COM_Invoke(pwb, "Document"), "parentWindow")
COM_Release(pwb),COM_Release(Document)
Break
}
COM_Release(pwb),COM_Release(Document)
}
COM_Release(psw),COM_Release(psh) ; release the objects each loop itineration
if parentWindow is integer
{
return parentWindow
}
else
{
Return A_LastError
}
}
;~ Navigate the given window
IE7_Navigate(parentWindow,url) ; begins navigation process and holds execution till page has loaded fully
{
;~ parent windw is a Dom window object
if parentWindow is integer
{
result:=COM_Invoke(parentWindow, "Navigate",url) ;execute the navigation returns SOK
IE7_readyState(parentWindow) ;Holds till document onload event is ready
Return result
}
}
IE7_ExecuteJS(parentWindow, JS_to_Inject, VarNames_to_Return="") ;execute some js on a tab returns comma delimited list of vars if specified
{
if parentWindow is integer
{
If JS_to_Inject
COM_Invoke(parentWindow, "execScript",JS_to_Inject)
If VarNames_to_Return
{
StringSplit, Vars_, VarNames_to_Return, `,
Loop, %Vars_0%
Ret .= COM_Invoke(parentWindow,Vars_%A_Index%) . ","
StringTrimRight, Ret, Ret, 1
Return Ret
}
Else
Return 0
}
Else
Return error
}
IE7_readyState(parentWindow) ;pauses till there is no loading activity returns DOM window handle
{
if parentWindow is integer
{
loop 120{ ;limit to 60 seconds
Sleep, 500
rdy:=IE7_ExecuteJS(parentWindow, "var rdy=document.readyState","rdy") ; best method
If (rdy = "complete") ;Better to use the document readystate more consistent page load results
break
}
Return 0
}
else
Return A_LastError
}
IE7_Quit(parentWindow) ;Close a DOM window handle
{
COM_Invoke(parentWindow, "execScript","window.opener='top';window.close();")
}
IE7_New(url) ;only if at least one IE window already exists return parentWindow js accessable object returns DOM window handle
{
run http://Google.com
winwait,Google
parentWindow:=IE7_Get("Google")
IE7_Navigate(parentWindow,url)
return parentWindow ; object handle
}
IE7_Click_Text(parentWindow,innerHTML) ; searches a tags and clicks first text it finds to match returns error if not found will also trigger readystate
{
js=
(
var links=document.links;
var count=links.length;
)
count1 := IE7_ExecuteJS(parentWindow, js, "count")
loop, % count1
{
js=
(
var text=document.links(%A_Index%-1).innerHTML;
)
text1 := IE7_ExecuteJS(parentWindow, js, "text")
IfNotInString,text1,%innerHTML%
Continue ;skip the rest and go to next loop
js=
(
document.links(%A_Index%-1).click();
)
IE7_ExecuteJS(parentWindow, js)
Break
}
IE7_readyState(parentWindow) ; wait for page change to finish
Return
}
IE7_Click_Element(parentWindow,ID1=0) ; clicks first element it finds to match returns error if not found will also trigger readystate
{
clickme=
(
if (isNaN("%ID1%")){ // determins if an index or id is entered
document.all("%ID1%").click();
}else{ // must be an index
document.all(%ID1%).click();
}
)
COM_Invoke(parentWindow, "execScript",clickme)
IE7_readyState(parentWindow) ; wait for page change to finish
Return
}
IE7_Button_click(parentWindow,value) ;Searches input tags for type button then compares the value with the sought text if found clicks returns error if not found will also trigger readystate
{
button_click=
(
var i=0;
while (i<document.all.length)
{
var tag=document.all(i).tagName;
if (tag.toLowerCase()=='input')
{
var typ=document.all(i).type;
if (typ.toLowerCase()=='button' || typ.toLowerCase()=='submit' || typ.toLowerCase()=='reset')
{
var myVal=document.all(i).value;
var theVal='%value%';
if (myVal.toLowerCase()==theVal.toLowerCase())
{
document.all(i).click(); //click the button
tag=undefined;
typ=undefined;
break; // end the loop
}
}
}
i=i+1;
}
)
IE7_ExecuteJS(parentWindow, button_click)
IE7_readyState(parentWindow) ; wait for page change to finish
Return
}
;~ IE7_Get_DOM(parentWindow,ID,val="innerHTML",method="ID" )
;~ parentWindow assigned by IE7_Get(title,url="http") and must be an integer that represents a dom window handle
;~ ID will be an element id, index of all
IE7_Get_DOM(parentWindow,ID1) ;gets DOM object by ID Tag and returns string or error
{
get_=
(
if (isNaN("%ID1%")){ // determins if an index or id is entered
var tag=document.all("%ID1%").tagName;
var i=1;
}else{ // must be an index
var tag=document.all(%ID1%).tagName;
var i=2;
}
var tag1=tag.toLowerCase();
switch(tag1)
{
case "input":
var t=1;
break;
case "textarea":
var t=1;
break;
case "select":
var t=1;
break;
default:
var t=2;
}
if(i==1 && t==1)
var myVal=document.all("%ID1%").value;
else if(i==2 && t==1)
var myVal=document.all(%ID1%).value;
else if(i==1 && t==2)
var myVal=document.all("%ID1%").innerHTML;
else if(i==2 && t==2)
var myVal=document.all(%ID1%).innerHTML;
var t=0;
var i=0;
var tag1=0;
var tag=0;
)
myVal:=IE7_ExecuteJS(parentWindow, get_,"myVal")
IE7_ExecuteJS(parentWindow, "var myVal='undefined';")
Return myVal
}
IE7_Set_DOM(parentWindow,ID1,val="innerHTML") ;gets DOM object by ID Tag and returns string or error
{
set_=
(
if (isNaN("%ID1%")){ // determins if an index or id is entered
var tag=document.all("%ID1%").tagName;
var i=1;
}else{ // must be an index
var tag=document.all(%ID1%).tagName;
var i=2;
}
var tag1=tag.toLowerCase();
switch(tag1)
{
case "input":
var t=1;
break;
case "textarea":
var t=1;
break;
case "select":
var t=1;
break;
default:
var t=2;
}
if(i==1 && t==1)
document.all("%ID1%").value='%val%';
else if(i==2 && t==1)
document.all(%ID1%).value='%val%';
else if(i==1 && t==2)
document.all("%ID1%").innerHTML='%val%';
else if(i==2 && t==2)
document.all(%ID1%).innerHTML='%val%';
var t=0;
var i=0;
var tag1=0;
var tag=0;
)
IE7_ExecuteJS(parentWindow, set_)
Return
}
IE7_SetFrame_Form_DOM(parentWindow,FRM,FOM,ID1,val=0) ;gets DOM object by ID Tag and returns string or error
{
if FRM is integer
ahkframe:="document.frames(" . FRM . ")"
Else
ahkframe:="document.frames('" . FRM . "')"
if FOM is integer
ahkform:=ahkframe . ".document.forms(" . FOM . ")"
Else
ahkform:=ahkframe . ".document.forms('" . FOM . "')"
if ID1 is integer
ahkele:=ahkform . ".elements(" . ID1 . ")"
Else
ahkele:=ahkform . ".elements('" . ID1 . "')"
tagName:=IE7_ExecuteJS(parentWindow, "var tagName=" . ahkele . ".tagName;" , "tagName")
teststring:="inputselecttextarea"
IfInString,teststring,%tagName%
domString := ahkele . ".value"
Else
domString := ahkele . ".innerHTML"
if val
Return IE7_ExecuteJS(parentWindow, "var oDom=" . domString . "='" . val . "';","oDom")
Else
Return IE7_ExecuteJS(parentWindow, "var oDom=" . domString . ";","oDom")
Return
}
IE7_SetFrame_DOM(parentWindow,FRM,ID1,val=0) ;gets DOM object by ID Tag and returns string or error
{
if FRM is integer
ahkframe:="document.frames(" . FRM . ")"
Else
ahkframe:="document.frames('" . FRM . "')"
if ID1 is integer
ahkele:=ahkframe . ".document.all(" . ID1 . ")"
Else
ahkele:=ahkframe . ".document.all('" . ID1 . "')"
;~ tagName:=IE7_ExecuteJS(parentWindow, "var tagName=" . ahkele . ".sourceIndex;" , "tagName")
;~ MsgBox % tagName
tagName:=IE7_ExecuteJS(parentWindow, "var tagName=" . ahkele . ".tagName;" , "tagName")
teststring:="inputselecttextarea"
IfInString,teststring,%tagName%
domString := ahkele . ".value"
Else
domString := ahkele . ".innerHTML"
if val
Return IE7_ExecuteJS(parentWindow, "var oDom=" . domString . "='" . val . "';","oDom")
Else
Return IE7_ExecuteJS(parentWindow, "var oDom=" . domString . ";","oDom")
Return
}
there are examples posted
i will once again re post but i cant emphasize enuff the importance or reading thru the entirety of this thread there is alot there
Code:
COM_Init()
run iexplore.exe http://www.autohotkey.com/
WinWait,AutoHotkey,,5
sleep,1000
myPageHandle:=IE7_Get("autohotkey")
;~ MsgBox % myPageHandle
IE7_readyState(myPageHandle) ; waits for onload event of a webpage even if an onload isnt fired
IE7_Click_Text(myPageHandle,"forum") ; cycles thru the links collection and clicksthe first text match it finds then waits for the page load to complete
IE7_Click_Text(myPageHandle,"search")
IE7_Set_DOM(myPageHandle,"search_keywords","PLEASE HELP!! why is my thingy not working as expected?") ;example of filling out a form
IE7_Button_click(myPageHandle,"search")
IE7_Click_Text(myPageHandle,"PLEASE HELP!! why is my thingy not working as expected?")
MsgBox, 262192, Meet the Robinsons, Please Read the first Post before asking me any questions, 5
IE7_Click_Text(myPageHandle,"search")
IE7_Set_DOM(myPageHandle,"search_keywords","Automation IE7 Navigation and Scripting with Tabs") ;example of filling out a form
IE7_Button_click(myPageHandle,"search") ; click a button labeled search and wait for the page to load
IE7_Click_Text(myPageHandle,"Wait for page to load before execute next command")
MsgBox, 262192, Automation IE7 Navigation and Scripting with Tabs, 5
COM_Term()
ExitApp
@ell
first of all dont take this wrong but
use code tagssecond
execScript is a method of a window object
so should be used on
oWin not oIE
incorrect
Code:
COM_Invoke(oIE,"execScript",JSexec)
correct
Code:
COM_Invoke(oWin,"execScript",JSexec)
otherwise very good looking script