AutoHotkey Community

It is currently May 26th, 2012, 8:57 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 75 posts ]  Go to page 1, 2, 3, 4, 5  Next
Author Message
PostPosted: June 24th, 2009, 8:48 am 
I'm trying to write a script to do this:

sample page code here: http://pastebin.com/mc4473d8

1. Auto-refresh the page about once per second.

2. sometimes when the page is refreshed the yes no boxes will appear, i need to recognize the yes box and click it, then click ok on the dialog box that pops up to confirm.

3. then the it would go back to refreshing itself and after successfully completing this 4 or 5 times, I'd like the script to kill itself. (Generally this will take approximately 1 hour to complete this 5 times)

Thank you in advance for your help


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2009, 7:26 pm 
Offline

Joined: March 8th, 2008, 11:36 am
Posts: 64
Location: Santa Barbara
The following may help:

Example of Navigating a Website
http://www.autohotkey.com/forum/viewtopic.php?t=42488

If a yes/no dialog box comes up, is there a window title for that dialog box? You could check to see if a window with that title exists, and if so then deal with it. (Rather than trying to click yes/no, there may be a keyboard shortcut that's easier. Possibly ctrl-Y or ctrl-N.)

Keep a counter and when the counter reaches 5 you can end the script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 25th, 2009, 12:48 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Quote:
sample page code here: http://pastebin.com/mc4473d8

Is that the actual website? Or could you provide a link to the website?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2009, 11:56 am 
You can use this Firefox addon: https://addons.mozilla.org/en-US/firefox/addon/3863


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2009, 11:59 am 
forgot to mention:

For page refreshes, use http://wiki.imacros.net/REFRESH

For clicking the browser dialogs, use http://wiki.imacros.net/ONDIALOG (should be added automatically during recording)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2009, 7:12 am 
Offline

Joined: June 24th, 2009, 9:15 am
Posts: 35
I can't provide the actual page because its an internal company site.

Thanks for your replies. Hopefully i can figure this stuff out.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2009, 7:29 am 
Offline

Joined: June 24th, 2009, 9:15 am
Posts: 35
How can I have it refresh the page until this appears "ID:ctl00_cph_content_dgOrders_ctl03_rbl_1" ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2009, 7:39 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Are you using IE? If so, this might help with step 1:
Code:
COM_Init() ; requires COM.ahk Library
pwd := GetWebBrowser()
loop
{   sleep 2000
   COM_Invoke(pwd, "Navigate", "javascript:location.reload(true)")
;   if . . .  check for dialog boxes
}

Note - Sean's GetWebBrowser() function can be found at http://www.autohotkey.com/forum/topic24930.html (2nd from bottom)
In this example, the IE webpage needs to be the active window for GetWebBrowser() to work.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2009, 8:14 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Quote:
How can I have it refresh the page until this appears "ID:ctl00_cph_content_dgOrders_ctl03_rbl_1" ?

Code:
COM_Init() ; requires COM.ahk Library
pwd := GetWebBrowser()
loop
{   COM_Invoke(pwd, "Navigate", "javascript:location.reload(true)")
   IEReady()
   if % COM_Invoke(pwd, "document.getElementById[ctl00_cph_content_dgOrders_ctl03_rbl_1]")
      break
}

You want to make sure the page is loaded before testing for "ID:ctl00_cph_content_dgOrders_ctl03_rbl_1". Check out this topic: http://www.autohotkey.com/forum/viewtopic.php?t=19256. I used Sean's IEReady() function (which is found in the first post). It doesn't work with every webpage, but there are other examples in that thread too.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2009, 9:07 am 
Offline

Joined: June 24th, 2009, 9:15 am
Posts: 35
yeah so, this is apparently all over my head.

i've got the COM.ahk, now what am i supposed to do with this GetWebBrowser function, does it need to be a separate file?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2009, 9:58 am 
Offline

Joined: October 21st, 2007, 4:32 am
Posts: 54
The COM.ahk belongs in your program files\autohotkey\lib folder.

Any script you right now can make use of the pre-scripted library of functions.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 28th, 2009, 9:39 pm 
Offline

Joined: June 24th, 2009, 9:15 am
Posts: 35
This is the first time I've worked with AHK, and i'm pretty lost.

This is what i've got so far
Code:
Run file:///C:\code.html

COM_Init() ; requires COM.ahk Library
pwd := GetWebBrowser()
loop
{   COM_Invoke(pwd, "Navigate", "javascript:location.reload(true)")
   IEReady()
   if % COM_Invoke(pwd, "document.getElementById[ctl00_cph_content_dgOrders_ctl03_rbl_1]")
      break
}



GetWebBrowser()
{
   ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, ahk_class IEFrame
   If Not   hIESvr
      Return
   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2,

"Uint", 1000, "UintP", lResult)
   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0,

"UintP", pdoc)
   IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
   pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)
   COM_Release(pdoc)
   Return   pweb
}

IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      If Not   hIESvr
         Return   """Internet Explorer_Server"" Not Found."
   }
   Else
   {
      WinGetClass, sClass, ahk_id %hIESvr%
      If Not   sClass == "Internet Explorer_Server"
         Return   "The specified control is not ""Internet Explorer_Server""."
   }

   COM_Init()
   If   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2,

"Uint", 1000, "UintP", lResult)
   &&   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0,

"UintP", pdoc)=0
   &&   pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}")
   {
      While,   COM_Invoke(pweb, "ReadyState") <> 4
      Sleep,   500
      While,   COM_Invoke(pweb, "document.readyState") <> "complete"
      Sleep,   500
      COM_Release(pweb)
   }
   COM_Release(pdoc)
   COM_Term()
   Return   pweb ? "DONE!" : False
}


and obviously, it doesn't work.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 29th, 2009, 5:20 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Quote:
yeah so, this is apparently all over my head.

Quote:
This is the first time I've worked with AHK, and i'm pretty lost.

That's quite alright. :D According to the Wiki, these are Advanced topoics - http://www.autohotkey.com/wiki/index.ph ... =Tutorials
You may want to check out "COM Tutorial by tank" & "Control/manipulate webpages using JavaScript by daonlyfreez"
Note - Tank's tutorial was written before the "Dot Syntax" was incorporated into the COM.ahk Library. Example:
Code:
COM_Invoke(pwd, "document.getElementById[Passwd]")
;would have been written:
COM_Invoke(COM_Invoke(pwd, "document"), "getElementById", "Passwd")


What version of IE are you working with? The IEReady() function usually works fine for me on IE 6, but it's not working well for me on IE 8. Perhaps try removing the IEReady() function for now, and use Sleep 5000 (or however long it takes for the page to refresh usually)

Example script:
Load www.Google.com. Run this code (Hotkey: ^d). This will keep refreshing every 3 seconds because the element doesn't exist.
Then pause the script, and click on the Gmail link on the top of the webpage. After this is loaded, unpause the script. The DONE! msgbox should display because now the element exists.
Code:
GetWebBrowser() ; written by Sean
{
   ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, ahk_class IEFrame
   If Not   hIESvr
      Return
   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)
   IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
   pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)
   COM_Release(pdoc)
   Return   pweb
}

^d::
COM_Init()
pwd := GetWebBrowser()
loop
{   COM_Invoke(pwd, "Navigate", "javascript:location.reload(true)")
    sleep 3000
   if % COM_Invoke(pwd, "document.getElementById[Passwd]")
      break
}
msgbox DONE!
return


:idea: EDIT :!:
Try completely loading the page you're working with, and run this script:
Code:
^d::
COM_Init()
pwd := GetWebBrowser()
msgbox % COM_Invoke(pwd, "ReadyState")
return

That is the value of "ReadyState" when the page is fully loaded. If this value is not 4, you may be able to alter the IEReady() function to fix the waiting until fully loaded problem:
Code:
IEReady(hIESvr = 0) ; written by Sean
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      If Not   hIESvr
         Return   """Internet Explorer_Server"" Not Found."
   }
   Else
   {
      WinGetClass, sClass, ahk_id %hIESvr%
      If Not   sClass == "Internet Explorer_Server"
         Return   "The specified control is not ""Internet Explorer_Server""."
   }

   COM_Init()
   If   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
   &&   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)=0
   &&   pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}")
   {
      While,   COM_Invoke(pweb, "ReadyState") <> 4 ; <-- Change 4 to different value
      Sleep,   500
      While,   COM_Invoke(pweb, "document.readyState") <> "complete"
      Sleep,   500
      COM_Release(pweb)
   }
   COM_Release(pdoc)
   COM_Term()
   Return   pweb ? "DONE!" : False
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 29th, 2009, 6:43 am 
Offline

Joined: June 24th, 2009, 9:15 am
Posts: 35
I've got IE7, but FFX is my default browser, which the script seems to use when I run it.

can you direct me somewhere I can get someone to write this script for me? I just don't have the time to learn how to use AHK right now. should I go to rentacoder.com or something? any help is appreciated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 29th, 2009, 7:12 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Your script runs FFX because of this line:
Code:
Run file:///C:\code.html

This will run the html file on the default browser. However, FFX is not a COM application; therefore, the COM.ahk Library won't do much good.

Quote:
can you direct me somewhere I can get someone to write this script for me?

:shock: Not too sure about that, especially since . . .
Quote:
I can't provide the actual page because its an internal company site.


One good thing is that Javascript will work with FFX. For instance, put this in the URL address bar, hit enter, and the page will refresh:
Code:
javascript:location.reload(true)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 75 posts ]  Go to page 1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, coinman, Google [Bot], oldbrother and 63 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group