| View previous topic :: View next topic |
| Do you find this group pf wrapper functions for IE Automation Usefull |
| no you suck |
|
8% |
[ 2 ] |
| need better Documentation |
|
29% |
[ 7 ] |
| What is DHTML i dont understand how this helps |
|
8% |
[ 2 ] |
| I use Firefox this is a stupid idea |
|
33% |
[ 8 ] |
| I know DHTML this is a reasonably good AHK adaption |
|
4% |
[ 1 ] |
| This is the best DHTML too in the AHK Forum |
|
16% |
[ 4 ] |
|
| Total Votes : 24 |
|
| Author |
Message |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Mon Aug 04, 2008 7:54 pm Post subject: |
|
|
| Quote: |
I highly recommend at least changing
Code (Copy):
IfWinExist Google
to
Code (Copy):
IfWinExist Google - Windows Internet
|
You are wrong. Not everyone has " - Windows Internet" as a postfix.
Your other suggestion however will work just fine. _________________ simplified csv - easy way to handle csv files. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 1033
|
Posted: Mon Aug 04, 2008 8:52 pm Post subject: |
|
|
- Windows Internet IE7
- Microsoft Internet previous versions
either way is a bad idea for the ifwinexist
2 things have to be true
the tab in question is active and the correct version of is has to be known
might be better to try this
| Code: | myPageHandle := IE7_Get("Google")
if not myPageHandle is integer
myPageHandle := IE7_New("www.google.com")
.... |
if you simply must use ifwinexist (there have been times for me)
| Code: | | ifwinexist,Google ahk_class IEFrame |
_________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 1033
|
Posted: Mon Aug 04, 2008 11:54 pm Post subject: |
|
|
Due to this string of conversations im revising the IE7_get function
a blank title will grab an active window/tab
and a pointer will only be returned if the window holds an html document
| Code: | IE7_Get(title="",url="http")
{
if not title ;test for a blank page_title
{
IfWinExist,ahk_class IEFrame ; ensure that an ie window exists
WinGetTitle,title,ahk_class IEFrame ;try grab an active ie window and use whatever tab is selected
Else
Return IE7_New("http://www.autohotkey.com/forum/viewtopic.php?t=30599") ; no window found just create a new window
}
;~ 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
}
}
|
edit i hadnt tested above so if you have copied before 89:55 pm eastern i have updated and tested since then _________________ Read this
Com
Automate IE7 with Tabs
Last edited by tank on Tue Aug 05, 2008 12:54 am; edited 2 times in total |
|
| Back to top |
|
 |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Tue Aug 05, 2008 12:19 am Post subject: |
|
|
| Code: | | a blank title will grab an active window/tab |
Last active would be better. _________________ simplified csv - easy way to handle csv files. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 1033
|
Posted: Tue Aug 05, 2008 12:30 am Post subject: |
|
|
ok more to the point my description was lacking it would be the last active
fixxed a typo in variable name _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
CannedCheese
Joined: 21 May 2008 Posts: 85
|
Posted: Tue Aug 05, 2008 12:50 am Post subject: |
|
|
| I'm trying to find a suitable public webpage to offer as an example, but I have occasional problems with IE7_ReadyState when accessing certain websites that utilize javascript. Pageloads will occasionally get stuck with "1 item (or is it image?) remaining", and never complete the load, and I get stuck waiting for a result forever. I've put together some ugly code that relies on timers to check if the load has timed out (gives it 20 seconds) and then reloads the page with IE7_Nav (is there a difference between IE7_Nav and IE7_Navigate? -- I'll have to look into it). Anyway, I am trying to find a public website that occasionally hangs (aol.com seems pretty bloated) for demonstration so that I can recreate this problem, and if no one knows a quick fix I'll hack together my code. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 1033
|
Posted: Tue Aug 05, 2008 1:01 am Post subject: |
|
|
First of all i do know what you mean
no need to give me an example
unfortunately the only thing you can do semi effectively is shorten my considerable amount of load wait time
| Code: | IE7_readyState(parentWindow) ;pauses till there is no loading activity returns DOM window handle
{
if parentWindow is integer
{
loop 60{ ;limit to 30 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
} |
the above shortens the hold to 30 seconds but i caustion against it
at no time should the readystate function cause you to hold over 60 seconds by default
essentially IE7_Nav and IE7_Navigate? get you the same result but the IE7_Nav initiates com for you and houses readystate within the same function _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
CannedCheese
Joined: 21 May 2008 Posts: 85
|
Posted: Tue Aug 05, 2008 1:15 am Post subject: |
|
|
I had actually modified the ie7_readystate function to take an optional parameter (waittime) like
| Code: | ie_7_readystate(parentwindow, WaitTime=30)
if parentWindow is integer
{
loop %WaitTime%{ ;limit to WaitTime/2 seconds |
when I first tried to solve my problem, but it was still hanging up so I gave up as I don't have a clue about COM and am still pretty DOM and Javascript retarded.
I'll look around and figure out a way to recreate the problem with a public webpage.
My workaround using a timer to check on readystate seems real sloppy and occasionally gets hung up itself, but it mostly works. I will post this soon. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 1033
|
Posted: Tue Aug 05, 2008 3:02 am Post subject: |
|
|
its not really sloppy on your part its the fool that wrote or maintains so poorly a web page that it never finishes loading
I really do beleive i know the problem you describ but the ready state function is not infinate
its limted to 1 full minute
in the past i have also done something like
| Code: | loop 120
{
sleep 500
len:=IE7_ExecuteJS(parentWindow, "var rdylngth=document.all.length", "rdylngth")
ifgreater,len,200 ;well any number that represents some number of tags less than what a fully loaded page might yeild
break
} |
one way to arive at your number is open the page and put
| Code: | | javascript:void(alert(document.all.length)) | in the address bar and hit enter i usually subtract 20 from this number and use it instead of 200 above
this is a very hackish way to do it but it does work when all else fails _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
CannedCheese
Joined: 21 May 2008 Posts: 85
|
Posted: Tue Aug 05, 2008 5:20 am Post subject: |
|
|
| So is 3700 a lot? |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 1033
|
|
| Back to top |
|
 |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Tue Aug 05, 2008 7:31 pm Post subject: |
|
|
Sorry i didn't look through your code at all so i might be completely off by saying this. If you are using "complete" as a ready state and this generates an issue as noted above, why not allow a second parameter?
example:
| Code: | | IE7_ReadyState(handle, state) | where state can be issued one of four parameters: loading, loaded, interactive, complete. This way if anyone is having an issue with "complete", instead can resort to "interactive" _________________ simplified csv - easy way to handle csv files. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 1033
|
Posted: Tue Aug 05, 2008 7:46 pm Post subject: |
|
|
well it really serves no purpos to use loading
you cannot interact with the page yet at this point
now if all you are doing is making sure that the data posted
i suppose you could change it to loaded
http://msdn.microsoft.com/en-us/library/ms534359(VS.85).aspx
sState String that receives one of the following values.uninitialized Object is not initialized with data.
loading Object is loading its data.
loaded Object has finished loading its data.
interactive User can interact with the object even though it is not fully loaded.
complete Object is completely initialized.
that said it could esily be altered in the way you suggest tho i cant see a real need to do anything aside from this
| Code: | IE7_readyState(parentWindow,complete=1) ;pauses till there is no loading activity returns DOM window handle
{
;~ if unset or 0 then complete will use loaded as a break point
if parentWindow is integer
{
loop 60{ ;limit to 30 seconds
Sleep, 500
rdy:=IE7_ExecuteJS(parentWindow, "var rdy=document.readyState","rdy") ; best method
If (rdy = (stat:=complete ? "complete" : "loaded") ;Better to use the document readystate more consistent page load results
break
}
Return 0
}
else
Return A_LastError
} |
let me know if that helps but at the very least you might add a 1 sec pause after if you choose loaded _________________ Read this
Com
Automate IE7 with Tabs |
|
| Back to top |
|
 |
CannedCheese
Joined: 21 May 2008 Posts: 85
|
Posted: Sun Aug 10, 2008 11:52 pm Post subject: |
|
|
I started my own post but I sort of think that this applies to those trying to integrate javascript into ahk, so I'm reposting it in this thread...
This may be a stupid question, or it may not be possible. What I'm trying to do is pass a variable's contents to a javascript instruction that, for means of readability, I want to keep in a continuation section. I'm using tank's awesome IE7 functions...
This should work...
| Code: |
IE7_ExecuteJS(myPageHandle, "for (i = 0; x <>'" name "'; i++){x=(document.getElementById('Table1').childNodes[1].childNodes[i].innerText); y+=(document.getElementById('Table1').childNodes[1].childNodes[i].childNodes[1].innerText)};", "y")
|
[edit] I don't know, maybe it should be %name% instead...
anyway...
My Javascript is pretty horrible so possibly i introduced a bug, but the idea is that i want to have the javascript code insert the value of name into the javascript...
The javascript section gets huge so i want to use a pretty continuation section... like
| Code: |
js =
(
for (i = 0; x <>" HOW DO I INSERT NAME HERE?
... etc...
; i++){x=(document.getElementById('Table1').childNodes[1].childNodes[i].innerText); y+=(document.getElementById('Table1').childNodes[1].childNodes[i].childNodes[1].innerText)};", "y")...
... etc.
|
Any help would be extremely appreciated... things look a lot prettier when I can include them in a variable/continuation section and pass that, instead of the 300 or 500 characters on 1 line that I'll end up needing. |
|
| Back to top |
|
 |
neXt
Joined: 18 Mar 2007 Posts: 463
|
Posted: Mon Aug 11, 2008 12:41 am Post subject: |
|
|
1) I don't fully understand what you are saying but if you trying to AHKs variable to JS then just wrap it in %% like you would normally do in AHK.
2) You don't have to write all JS code in 1 line, it can be done this way:
| Code: |
IE7_ExecuteJS(handle, JsCode)
JsCode =
(
javascript goes here;
break it in multiple lines;
tab it or whatever else you wanna do;
it will work and improve readability;
)
|
_________________ simplified csv - easy way to handle csv files. |
|
| Back to top |
|
 |
|