Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Automation IE7 Navigation and Scripting with Tabs


  • This topic is locked This topic is locked
214 replies to this topic

Poll: Do you find this group pf wrapper functions for IE Automation Usefull (35 member(s) have cast votes)

Do you find this group pf wrapper functions for IE Automation Usefull

  1. no you suck (3 votes [8.33%])

    Percentage of vote: 8.33%

  2. need better Documentation (10 votes [27.78%])

    Percentage of vote: 27.78%

  3. What is DHTML i dont understand how this helps (4 votes [11.11%])

    Percentage of vote: 11.11%

  4. I use Firefox this is a stupid idea (10 votes [27.78%])

    Percentage of vote: 27.78%

  5. I know DHTML this is a reasonably good AHK adaption (2 votes [5.56%])

    Percentage of vote: 5.56%

  6. This is the best DHTML too in the AHK Forum (7 votes [19.44%])

    Percentage of vote: 19.44%

Vote
neXt
  • Members
  • 549 posts
  • Last active: May 20 2015 02:38 AM
  • Joined: 18 Mar 2007

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.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007
- 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
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)
ifwinexist,Google ahk_class IEFrame

Never lose.
WIN or LEARN.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007
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
IE7_Get(title="",url="http") 
{ 
	[color=blue]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		
	}[/color]
;~    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
Never lose.
WIN or LEARN.

neXt
  • Members
  • 549 posts
  • Last active: May 20 2015 02:38 AM
  • Joined: 18 Mar 2007
a blank title will grab an active window/tab
Last active would be better.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007
ok more to the point my description was lacking it would be the last active
fixxed a typo in variable name
Never lose.
WIN or LEARN.

CannedCheese
  • Members
  • 120 posts
  • Last active: Sep 24 2014 04:31 PM
  • Joined: 21 May 2008
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.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007
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
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
Never lose.
WIN or LEARN.

CannedCheese
  • Members
  • 120 posts
  • Last active: Sep 24 2014 04:31 PM
  • Joined: 21 May 2008
I had actually modified the ie7_readystate function to take an optional parameter (waittime) like
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.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007
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
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
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
Never lose.
WIN or LEARN.

CannedCheese
  • Members
  • 120 posts
  • Last active: Sep 24 2014 04:31 PM
  • Joined: 21 May 2008
So is 3700 a lot?

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007
godaddys home page has that many
Never lose.
WIN or LEARN.

neXt
  • Members
  • 549 posts
  • Last active: May 20 2015 02:38 AM
  • Joined: 18 Mar 2007
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:
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"

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007
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

<!-- m -->http://msdn.microsof.../ms534359(VS.85<!-- m -->).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

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
Never lose.
WIN or LEARN.

CannedCheese
  • Members
  • 120 posts
  • Last active: Sep 24 2014 04:31 PM
  • Joined: 21 May 2008
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...
IE7_ExecuteJS(myPageHandle, "for (i = 0; x <>'" [color=red]name [/color]"'; 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
js = 
(
for (i = 0; x <>" [color=red]HOW DO I INSERT NAME HERE?[/color]

... 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.

neXt
  • Members
  • 549 posts
  • Last active: May 20 2015 02:38 AM
  • Joined: 18 Mar 2007
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:

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;
)